[Bug c++/52036] C++11 allows template parameters to have internal linkage
mimomorin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Feb 20 14:55:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52036
Michel Morin <mimomorin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mimomorin at gmail dot com
--- Comment #11 from Michel Morin <mimomorin at gmail dot com> ---
The internal linkage testcase
template <typename T, const T &val> class TestClass {
/* ... */
};
constexpr float pi = 3.14;
int main()
{
TestClass<float, pi> test;
}
compiles successfully from GCC 6.
However, Richard's testcase (i.e. testcase in the Standard)
template<class T, const char* p> class X {
/* ... */
};
const char p[] = "Vivisectionist";
X<int,p> x;
fails to compile even on GCC 7 (in C++11/14 modes) with this error message
error: the value of 'p' is not usable in a constant expression
X<int,p> x;
^
note: 'p' was not declared 'constexpr'
const char p[] = "Vivisectionist";
As the message suggests, if `p` is declared as `constexpr` it compiles fine.
Note that in a C++1z mode (from GCC 5) it compiles fine without `constexpr`.
More information about the Gcc-bugs
mailing list