Consider the following code:
struct Undefined;
template <typename T>
void TemplateFunction()
{
Undefined obj;
}
int main()
{
return 0;
}
I was always under the impression that template functions and template methods (or methods part of a template class) will only be checked for syntax (unless they are instantiated) in which case the above code should compile.
Problem is, it does not compile with Xcode (ver: 4.3.2, using the LLVM compiler) and now I am wondering whether the above code is non-standard i.e. it should not compile on a compiler conforming to the C++03 standard? The error from Xcode is:
Variable has incomplete type “Undefined”
Note that in the original code, the undefined object is part of the static assertion.
The compiler is right in rejecting the code, even though other compilers will gladly accept it. In particular the quote would be within §14.6[temp.res]/8
That is, the template is ill-formed although the compiler is not required to diagnose it.