Suppose the code:
template <class T>
class X { };
int main(void) {
X<class {
int a;
}> x;
return 0;
}
g++ 5.1 gives the following error message:
prog.cpp: In function 'int main()':
prog.cpp:5:10: error: types may not be defined in template arguments
X<class {
^
prog.cpp:7:2: error: expected ';' after class definition
}> x;
^
prog.cpp:7:2: error: expected template-argument before ';' token
prog.cpp:7:2: error: expected '>' before ';' token
prog.cpp:7:2: error: 'main()::<anonymous class>' is/uses anonymous type
prog.cpp:7:2: error: trying to instantiate 'template<class T> class X'
prog.cpp:7:2: error: expected '::' before ';' token
prog.cpp:7:2: error: expected identifier before ';' token
prog.cpp:7:3: error: expected primary-expression before '>' token
}> x;
^
prog.cpp:7:5: error: 'x' was not declared in this scope
}> x;
^
The second line of the error output says that we can't define types in template arguments. Why is it invalid? (I mean, I know it's invalid in the standard, but what's the reason for that?)