https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64446

            Bug ID: 64446
           Summary: Misleading error message when inheriting from a
                    template class w/o the template params
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petschy at gmail dot com

When compiling the under code, g++ gives a misleading error message:

$ g++-5.0.0 -Wall 20141230-templ_base.cpp 
20141230-templ_base.cpp:7:1: error: expected class-name before ‘{’ token

'Base' is definitely a valid class name.

The problem is that the name given is a class, but it's a template and the
template argument is missing.

However, in the second case, when inheriting from Base2 and only one template
argument is given of the two, the error message is OK: wrong number of template
arguments (1, should be 2).

Something similar would be desirable in the first case, not to waste time
staring at the screen, searching for a typo in the class name and finding none.
Like '<classname> is a template but no template arguments are given'.

$ g++-5.0.0 -v
Using built-in specs.
COLLECT_GCC=g++-5.0.0
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++ --disable-multilib
--program-suffix=-5.0.0
Thread model: posix
gcc version 5.0.0 20141222 (experimental) (GCC) 

4.9 and 4.8 gives the same misleading error message.

----8<----8<----8<----8<----
template<typename T>
struct Base
{
};

struct Foo : Base
{       // error: expected class-name before ‘{’ token
};

template<typename T, typename U>
struct Base2
{
};

struct Foo2 : Base2<int> // OK: wrong number of template arguments (1, should
be 2)
{       
};

Reply via email to