#include "test.h" #include #include #include #include template void test(const char* expected, int line) { const char *mangled = typeid(T).name(); int status = 0; using abi::__cxa_demangle; char* demangled = __cxa_demangle(mangled, 0, 0, &status); printf("mangled='%s' demangled='%s', status=%d\n", mangled, demangled, status); free(demangled); TEST_LOC(status == 0, "should be able to demangle", __FILE__, line); TEST_LOC(demangled != 0, "should be able to demangle", __FILE__, line); if (!demangled) { /* Don't dereference NULL in strcmp() */ return; } TEST_LOC(strcmp(expected, demangled) == 0, "should be able to demangle", __FILE__, line); TEST_LOC(strcmp(mangled, demangled) != 0, "should be able to demangle", __FILE__, line); } namespace N { template class Templated { virtual ~Templated() {}; }; } void test_demangle(void) { using namespace N; test("int", __LINE__); test("char [4]", __LINE__); test("char []", __LINE__); test, 8> >( "N::Templated, 8>", __LINE__); test >( "N::Templated", __LINE__); }