Std :: string & as a template parameter and abi_tag in gcc 5

Consider the following code snippet (test1.cpp):

#include <string>

extern std::string test_string;

template<std::string &s>
class test{
public:
   static void bar(){ }
};

std::string test_string("test string");
void foo(){test<test_string>::bar();}

Now let's move on to the order of the last two lines of code (test2.cpp):

#include <string>

extern std::string test_string;

template<std::string &s>
class test{
public:
   static void bar(){ }
};

void foo(){test<test_string>::bar();}
std::string test_string("test string");

Nothing should change. But if you look through objdump into a compiled file, you will see the difference:

objdump -t -C test*.o | grep bar

In one case, a template test was created as:

test<test_string[abi:cxx11]>::bar()

and in another:

test<test_string>::bar()

both files can only be compiled with

gcc -c test*.cpp

Thus, a reference to std :: string as a template parameter is considered unmarked if it is just declared extern. And it is considered as marked after determination.

Some classes in my project are created twice, where there should be only one class. This is pretty unpleasant.

gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2)

Is this a bug in the compiler? Or is this the expected behavior? What could be the workaround?

+4
1

; GCC Bugzilla, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66971 - , thread_local, .

, , :

template<std::string *s> class test { .... };
void foo(){test<&test_string>::bar();}

: gcc https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69621

+2

Source: https://habr.com/ru/post/1627000/


All Articles