The following code compiles fine in GCC 6.3 with -std=c++11.
template <typename T>
struct MetaFunction
{
static int value;
};
#define MY_MACRO(T) (MetaFunction<T>::value)
template <class T, const int* p = &MY_MACRO(T)>
struct Foo
{
void DoSomething()
{
}
};
int main()
{
Foo< int > f;
f.DoSomething();
}
But if -std=c++14 is specified then it emits the following error:
main.cpp:19:14: error: '& MetaFunction<int>::value' is not a valid template argument for 'const int*' because it is not the address of a variable
Foo< int > f;
^
Clang 3.8 gives a similar error whether -std=c++11 or -std=c++14 is specified.
main.cpp:11:36: error: non-type template argument does not refer to any declaration
template <class T, const int* p = &MY_MACRO(T)>
^~~~~~~~~~~
Changing MY_MACRO(T)
from (MetaFunction<T>::value)
to MetaFunction<T>::value
fixes the problem.
Which compiler is correct here? Does the C++14 standard include a change that makes GCC's behaviour expected? Or is Clang right to emit an error under C++11 as well?