public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44283]  New: bad error recovery for explicit template instantiation in wrong namespace
@ 2010-05-26 13:42 jwakely dot gcc at gmail dot com
  0 siblings, 0 replies; only message in thread
From: jwakely dot gcc at gmail dot com @ 2010-05-26 13:42 UTC (permalink / raw)
  To: gcc-bugs

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)


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<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'

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<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

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-05-26 13:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-26 13:42 [Bug c++/44283] New: bad error recovery for explicit template instantiation in wrong namespace jwakely dot gcc at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).