[Bug c++/44283] bad error recovery for explicit template instantiation in wrong namespace
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Apr 12 12:35:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44283
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-12 12:35:07 UTC ---
(In reply to comment #0)
> namespace NS
> {
> typedef int X;
>
> template<typename T> void f(X f, T t) { }
> }
>
> template void f(X, int); // (1)
>
> template void f(int, char); // (2)
Clang does very well for this:
t.cc:8:15: error: explicit instantiation of 'f' does not refer to a function
template, member function, member
class, or static data member
template void f(X, int); // (1)
^
t.cc:10:15: error: explicit instantiation of 'f' does not refer to a function
template, member function,
member class, or static data member
template void f(int, char); // (2)
^
2 errors generated.
> If the invalid instantiation is for a class template the diagnostic is fine:
>
> namespace NS
> {
> template<typename T> struct S;
> }
>
> template struct S<X>;
>
> bug2.cc:6:17: error: 'S' is not a template
> bug2.cc:6:19: error: 'X' was not declared in this scope
> bug2.cc:6:17: error: explicit instantiation of non-template type 'S'
Clang is similar:
t.cc:6:19: error: use of undeclared identifier 'X'
template struct S<X>;
^
t.cc:6:17: error: explicit instantiation of non-template struct 'S'
template struct S<X>;
^
2 errors generated.
> namespace NS
> {
> template<int N> void g() { }
> }
>
> template void g<0>();
>
> bug3.cc:6:15: error: variable or field 'g' declared void
> bug3.cc:6:16: error: expected ';' before '<' token
Clang is not much better here:
t.cc:6:16: error: expected ';' after top level declarator
template void g<0>();
^
1 error generated.
EDG's diagnostics are still the best for these examples.
More information about the Gcc-bugs
mailing list