From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2412 invoked by alias); 26 May 2010 13:42:17 -0000 Received: (qmail 2371 invoked by uid 48); 26 May 2010 13:42:01 -0000 Date: Wed, 26 May 2010 13:42:00 -0000 Subject: [Bug c++/44283] New: bad error recovery for explicit template instantiation in wrong namespace X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jwakely dot gcc at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-05/txt/msg02927.txt.bz2 namespace NS { typedef int X; template void f(X f, T t) { } } template void f(X, int); // (1) template void f(int, char); // (2) The code is invalid, the explicit instantiations should be inside NS or should be qualified e.g. template void NS::func(X, int); But the diagnostic for instantiation (1) is unhelpful: bug.cc:8:17: error: variable or field 'f' declared void bug.cc:8:16: error: expected ';' before '(' token This is closely related to Bug 16663 but the diagnostic for (2) implies it might be possible to improve things without fixing bug 16663, as this is much better: bug.cc:10:26: error: 'f' is not a template function Is it possible to give the same "is not a template function" diagnostic for (1)? Comeau does significantly better, reporting: identifier "X" is undefined and "f" is not a class or function template name in the current scope If the invalid instantiation is for a class template the diagnostic is fine: namespace NS { template struct S; } template struct S; 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' The only improvement I would make would be to add something like "in this scope" to the first error. Here's another bad diagnostic for instantiating a template function, which doesn't have any undeclared type: namespace NS { template 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 Surely it's possible to say "g is not a template function" when the compiler sees "template ... g<...>" ? Comeau is much better again: "ComeauTest.c", line 6: error: g is not a template, Should it be XX::g?, where XX is some namespace? Did you #include the right header? template void g<0>(); ^ "ComeauTest.c", line 6: error: invalid explicit instantiation declaration template void g<0>(); ^ -- Summary: bad error recovery for explicit template instantiation in wrong namespace Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jwakely dot gcc at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44283