Bug 89620 - Add fix-it hint for missing comma in template argument list
Summary: Add fix-it hint for missing comma in template argument list
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2019-03-07 11:36 UTC by Jonathan Wakely
Modified: 2019-03-07 21:19 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2019-03-07 11:36:44 UTC
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.