libstdc++ Chapter 28. Demangling example

Jonny Grant jg@jguk.org
Fri Mar 31 20:38:43 GMT 2023



On 31/03/2023 17:18, Jonathan Wakely wrote:
> On Fri, 31 Mar 2023 at 16:24, Jonny Grant <jg@jguk.org> wrote:
>>
>> Hello
>>
>> I tried out this code. Maybe I'm doing something wrong?
>>
>> https://godbolt.org/z/Y78h4f1W6
>>
>> https://gcc.gnu.org/onlinedocs/gcc-12.2.0/libstdc++/manual/manual/ext_demangling.html
>>
>> However only get reduced output after status -2 is returned:
>>
>> std::bad_exception      =>
>>
>> Looks like std::cout gets broken by the nullptr realname (that's a frustration). So I put an if(realname) in the godbolt link above.
> 
> N.B. passing a null pointer to printf("%s", ptr) is undefined.
> Printing "(null)" is not required by the standards.
> 
> Anyway, the exception classes haven't printed their mangled name for
> many many years, if they ever did. Only the second part of the
> example, using typeid, is valid.

Ok I see. Is it better that the std::bad_exception part of the example is removed?

c++filt doesn't demangle St13bad_exception either.

>> Maybe it's also a good time to update the example abi::__cxa_demangle call from those 0 parameters to be NULL?
> 
> Maybe nullptr.

ok


I noticed in libstdc++-v3/libsupc++/cxxabi.h

   *  @note The same demangling functionality is available via
   *  libiberty (@c <libiberty/demangle.h> and @c libiberty.a) in GCC
   *  3.1 and later, but that requires explicit installation (@c
   *  --enable-install-libiberty) and uses a different API, although
   *  the ABI is unchanged.

This refers to GCC 3.1 from 2002, is it safe enough to now remove that GCC 3.1 comment? 

Regards, Jonny


More information about the Libstdc++ mailing list