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

            Bug ID: 89620
           Summary: Add fix-it hint for missing comma in template argument
                    list
           Product: gcc
           Version: 9.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, typename U> struct pair { };

pair<decltype(1) decltype(1)> p;


x.cc:3:18: error: two or more data types in declaration of ‘type name’
 pair<decltype(1) decltype(1)> p;
                  ^~~~~~~~
x.cc:3:29: error: wrong number of template arguments (1, should be 2)
 pair<decltype(1) decltype(1)> p;
                             ^
x.cc:1:41: note: provided for ‘template<class T, class U> struct pair’
 template<typename T, typename U> struct pair { };
                                         ^~~~

G++ notices there are two "data types" where one is expected, but also that one
template argument is given where two are expected. It could suggest a comma
between the two type names, which would solve both problems.


For this code, clang suggests there's a missing '>' between the types, which
doesn't actually fix the problem:

x.cc:3:18: error: expected '>'
pair<decltype(1) decltype(1)> p;
                 ^
x.cc:3:18: error: expected unqualified-id
2 errors generated.


For a similar case without decltype G++ gives the same errors, but clang says
something different:

x.cc:3:10: error: cannot combine with previous 'int' declaration specifier
pair<int int> p;
         ^
x.cc:3:1: error: too few template arguments for class template 'pair'
pair<int int> p;
^
x.cc:1:41: note: template is declared here
template<typename T, typename U> struct pair { };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        ^
2 errors generated.

Reply via email to