Commit 6643a9f1 authored by Dominik Charousset's avatar Dominik Charousset

Make template checks compiler-independent

parent c3325cb5
...@@ -49,6 +49,13 @@ void global_fun() { ...@@ -49,6 +49,13 @@ void global_fun() {
CHECK_FUN_PREFIX("GLOBAL"); CHECK_FUN_PREFIX("GLOBAL");
} }
// Little helper that allows us to write a single check for all compilers.
// Clang expands template parameters in __PRETTY_FUNCTION__, while GCC does
// not. For example, Clang would produce "void foo<int>::bar()", while GCC
// would produce "void foo<T>::bar() [with T = int]". A type called T gives
// us always the same ouptut for the prefix.
struct T {};
namespace { namespace {
struct fixture { struct fixture {
...@@ -92,8 +99,8 @@ const int& ref_fun(const int& x) { ...@@ -92,8 +99,8 @@ const int& ref_fun(const int& x) {
template <class T> template <class T>
struct tpl { struct tpl {
static void run(std::string t_name) { static void run() {
CHECK_FUN_PREFIX("$.tpl<" + t_name + ">"); CHECK_FUN_PREFIX("$.tpl<T>");
} }
}; };
...@@ -115,8 +122,8 @@ const int& ref_fun(const int& x) { ...@@ -115,8 +122,8 @@ const int& ref_fun(const int& x) {
template <class T> template <class T>
struct tpl { struct tpl {
static void run(std::string t_name) { static void run() {
CHECK_FUN_PREFIX("$.foo.tpl<" + t_name + ">"); CHECK_FUN_PREFIX("$.foo.tpl<T>");
} }
}; };
...@@ -201,15 +208,11 @@ CAF_TEST(render_fun_prefix) { ...@@ -201,15 +208,11 @@ CAF_TEST(render_fun_prefix) {
fun(); fun();
ptr_fun(nullptr); ptr_fun(nullptr);
ref_fun(i); ref_fun(i);
tpl<int>::run("int"); tpl<T>::run();
tpl<unsigned int>::run("unsigned%20int");
tpl<tpl<signed char>>::run("$.tpl<signed%20char>");
foo::fun(); foo::fun();
foo::ptr_fun(nullptr); foo::ptr_fun(nullptr);
foo::ref_fun(i); foo::ref_fun(i);
foo::tpl<int>::run("int"); foo::tpl<T>::run();
foo::tpl<unsigned int>::run("unsigned%20int");
foo::tpl<foo::tpl<signed char>>::run("$.foo.tpl<signed%20char>");
} }
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment