https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106631
Bug ID: 106631
Summary: Unhelpful diagnostic on variable template
specialization with unknown name
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
Short example:
template <class T>
constexpr bool trait = true;
template <>
constexpr bool triat<int> = false;
Note the typo on triat.
The current error message gcc provides is:
<source>:5:21: error: expected initializer before '<' token
5 | constexpr bool triat<int> = false;
| ^
Which is... technically true. Given that triat doesn't exist as a variable
template, the next thing coming up needs to be an initializer for it, since
this is really a declaration. But the intent was for it to specialize trait -
it seems like it's more likely that this kind of error would come from getting
the name of the variable template wrong rather than spelling the initializer
incorrectly?
So something like:
<source>:5:21: error: unknown variable template 'triat' being specialized
5 | constexpr bool triat<int> = false;
| ^~~~~
note: did you mean trait?
Would be much more helpful.