There is this code:
class A;
template <class T>
void fun() {
A a;
}
class A {
public:
A() { }
};
int main() {
fun<int>();
return 0;
}
g++ 4.5 and g++ 4.7 compiles this without error. But clang++ 3.2 (trunk) gives this error:
main.cpp:5:6: error: variable has incomplete type 'A'
A a;
^
main.cpp:1:7: note: forward declaration of 'A'
class A;
^
Which compiler is right then according to C++ standard?
Both are correct. This is an ill-formed program. Emphasis mine:
That clang++ and other compilers do issue a diagnostic here is a nice-to-have added feature, but a diagnosis is not mandatory. That clause “the program is ill-formed; no diagnostic is required” gives a compiler developer free reign to do just about anything in such circumstances and still be compliant.