C++ Logo


Advanced search

Re: [std-proposals] std::typeid_except ( Paper Attached )

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 02 Mar 2024 17:59:22 -0800
On Saturday, 2 March 2024 16:36:41 PST Frederick Virchanza Gotham via Std-
Proposals wrote:
> An exception is thrown from somewhere, and I can
> at least see the type's name:
> char const *const plugin_name = "FieryShadow"; // plugin name
> not known until runtime
> catch(...)
> {
> type_info const &ti = typeid_except();
> if ( strstr( ti.name(), plugin_name ) ) throw
> std::runtime_error("exception thrown from active plugin");
> }

First, the request is that you add the motivation to the paper, not reply by

Second, this example will NEVER match, no matter what you name your class,
because typeinfo::name() returns an ABI-specific string. That means you need an
ABI-specific encoding of the string to compare to on compilation or an ABI-
specific decoding on use, at runtime. If you're going to do this with ABI-
specific code, then you need to explain in your paper that there's no already-
available ABI-specific way to do what you want to do, or that the ABI-specific
additions required are minor and acceptable. Either way, you'll need to deal
with that in the example, but the need to have non-standard code in the
example about adding a feature to the example will lessen your proposal's
value. Also note your example talks about DSOs, which are not in the Standard

Third, comparing classes by name is poor programming practice. What happens if
the exception class in question was in an unnamed namespace? How do you
distinguish then two classes of the same name from each other? And because you
said DSO, you *can* have non-unnamed-namespace classes of the same name.

Try to think of more standards-compliant and less fragile examples.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2024-03-03 01:59:44