Skip to content

Instantly share code, notes, and snippets.

@marty1885
Last active June 30, 2021 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marty1885/c9b2faa49c35c53909048bf08e080607 to your computer and use it in GitHub Desktop.
Save marty1885/c9b2faa49c35c53909048bf08e080607 to your computer and use it in GitHub Desktop.
#include <cxxabi.h>
#include <iostream>
void demangle_name(const std::string& mangled_name)
{
std::size_t len = 0;
int status = 0;
auto name = __cxxabiv1::__cxa_demangle(mangled_name.c_str(), nullptr, &len, &status);
if (status == 0)
{
std::cout << "demangled name:" << name << "\n";
}
else
{
std::cout << "demangle error\n";
}
std::free(name);
}
template <typename T>
void demangle(T &&v)
{
std::size_t len = 0;
int status = 0;
auto name = __cxxabiv1::__cxa_demangle(typeid(T).name(), nullptr, &len, &status);
if (status == 0)
{
std::cout << "demangled name:" << name << "\n";
}
else
{
std::cout << "demangle error\n";
}
std::free(name);
}
void f1(std::string &s1) {}
void f2(std::string &&s1) {}
int main()
{
demangle(f1); // Good on FreeBSD 12. Fail on FreeBSD 13
demangle(f2); // Fail on FreeBSD 12. Fail on FreeBSD 13
demangle_name("i"); // Fail on FreeBSD 13
demangle_name("8SayHello"); // Fail on FreeBSD 13
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment