https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114934
Bug ID: 114934
Summary: Error message for expected unqualified-id could be
improved
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
Suppose I misspelled an extra colon for the namespace
(https://godbolt.org/z/q3b7531q3):
#include <tuple>
#include <string>
using Tuple = std::tuple<std:::string, int>;
GCC gives:
<source>:4:43: error: template argument 1 is invalid
4 | using Tuple = std::tuple<std:::string, int>;
| ^
Although it is not stated why it is invalid, it is still acceptable.
Clang gives:
<source>:4:31: error: expected unqualified-id
4 | using Tuple = std::tuple<std:::string, int>;
| ^
It correctly points out the location of the issue which is nice.
However, I changed it to the following (https://godbolt.org/z/zfoqeoxE3):
#include <tuple>
#include <string>
using Pair = std::pair<std:::string, int>;
GCC will give:
<source>:4:41: error: wrong number of template arguments (1, should be 2)
4 | using Pair = std::pair<std:::string, int>;
|
This is unkind because it doesn't indicate which one is invalid, but rather the
*wrong number* of arguments. This can be very confusing to users who haven't
discovered the typo, as there are indeed 2 template parameters here (which can
make debugging extremely difficult if there are plenty of template parameters
in the template list)