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

            Bug ID: 101519
           Summary: Improve diagnostic for template name used as base
                    class
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

template<typename T> struct A { };
template<typename T> struct B : A { };

a.C:2:35: error: expected class-name before ‘{’ token
    2 | template<typename T> struct B : A { };
      |                                   ^

While the error is technically correct, it would be more helpful to point out
that a template argument list is expected.


Clang does not better than GCC:

a.C:2:33: error: expected class name
template<typename T> struct B : A { };
                                ^
1 error generated.

But EDG does well:

"a.C", line 2: error: argument list for class template "A" is missing
  template<typename T> struct B : A { };
                                  ^

"a.C", line 2: error: not a class or struct name
  template<typename T> struct B : A { };
                                  ^

2 errors detected in the compilation of "a.C".


I think the current error would be fine if it was followed by a note:

note: 'A' is a class template; add a template argument list to use it as a
base-class

Reply via email to