The following code compiles in GCC 6.3 at -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 given, 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)>
^~~~~~~~~~~
A change MY_MACRO(T)from (MetaFunction<T>::value)to MetaFunction<T>::valuefixes the problem.
Which compiler is right here? Does the C ++ 14 standard include a change that makes GCC behavior expected? Or is Clang entitled to emit an error in C ++ 11?
source
share