1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "test.h"
#include <cxxabi.h>
#include <stdio.h>
#include <stdlib.h>
#include <list>
template <typename T> 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<typename T, int U>
class Templated {
virtual ~Templated() {};
};
}
void test_demangle(void)
{
using namespace N;
test<int>("int", __LINE__);
test<char[4]>("char [4]", __LINE__);
test<char[]>("char []", __LINE__);
test<Templated<Templated<long, 7>, 8> >(
"N::Templated<N::Templated<long, 7>, 8>", __LINE__);
test<Templated<void(long), -1> >(
"N::Templated<void (long), -1>", __LINE__);
}
|