I have been using some demangling code already for while to help with some debugging without having to write thousands of lines with dynamic casts or having to implement virtual functions which return the class name.
template <class CLASS>
std::string getClassName(CLASS &theObject)
{
int status = 0;
// Convert real name to readable string
char *realName = abi::__cxa_demangle(typeid(theObject).name(), nullptr,
nullptr, &status);
ASSERT(status == 0); // Assert for success
VERIFY(realName, return std::string());
// Return as string + prevent memory leaks!
const std::string result(realName);
free(realName);
return result;
}
The idea behind this code is simple, to output the class we are actually using. Though after switching to Ubuntu 14.04 I was no longer able to compile using clang and the c++-11/c++-14 standard, so I've switched to using the libc++ instead of libstdc++.
After switching to libc++, I've noticed that when I demangle 'std::string' it no longer outputs 'std::string', though instead it outputs:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >
Off course this is correct, since std::string is a typedef for std::basic_string. Though as far as I can see in both libc++ as libstdc++ this defined the same way, using the typedef. So I don't really understand why this demangling has changed by switching to the libc++.
Has someone an idea why this is different and how to get 'std::string' if CLASS would be 'std::string', and 'myTemplate' when CLASS would be 'myTemplate'?
Tnx in advance!
JVApen