DarkflameServer/dCommon/Type.cpp

28 lines
521 B
C++
Raw Normal View History

#include "Type.h"
#ifdef __GNUG__
#include <cstdlib>
#include <memory>
#include <cxxabi.h>
std::string demangle(const char* name) {
2022-07-28 13:39:57 +00:00
int status = -4; // some arbitrary value to eliminate the compiler warning
2022-07-28 13:39:57 +00:00
// enable c++11 by passing the flag -std=c++11 to g++
std::unique_ptr<char, void(*)(void*)> res{
abi::__cxa_demangle(name, NULL, NULL, &status),
std::free
};
2022-07-28 13:39:57 +00:00
return (status == 0) ? res.get() : name;
}
#else
// does nothing if not g++
std::string demangle(const char* name) {
2022-07-28 13:39:57 +00:00
return name;
}
#endif