https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124412
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2026-03-09
Ever confirmed|0 |1
Summary|different and confusing |Diagnostics for invalid
|diagnostic order for = 0 / |pure specifiers should be
|= 0u inside class vs at |improved
|namespace scope |
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang does better, only giving 4 errors, not 5:
<source>:2:8: error: 'h' is not virtual and cannot be declared pure
2 | void h() = 0;
| ^ ~
<source>:3:8: error: initializer on function does not look like a
pure-specifier
3 | void j() = 0u;
| ^ ~~
<source>:6:6: error: illegal initializer (only variables can be initialized)
6 | void h() = 0;
| ^
<source>:7:6: error: illegal initializer (only variables can be initialized)
7 | void j() = 0u;
| ^
4 errors generated.
EDG does well, giving 4 errors and not bothering to mention the 0u at all,
because changing it to 0 wouldn't make the code valid:
"<source>", line 2: error: pure specifier ("= 0") allowed only on virtual
functions
void h() = 0;
^
"<source>", line 3: error: pure specifier ("= 0") allowed only on virtual
functions
void j() = 0u;
^
"<source>", line 6: error: function "h" may not be initialized
void h() = 0;
^
"<source>", line 7: error: function "j" may not be initialized
void j() = 0u;
^
4 errors detected in the compilation of "<source>".
And MSVC seems somewhat consistent with EDG, although mentioning "abstract
override" here isn't helpful, and 'constant' is utterly unhelpful:
<source>(2): error C2253: 'A::h': pure specifier or abstract override specifier
only allowed on virtual function
<source>(3): error C2253: 'A::j': pure specifier or abstract override specifier
only allowed on virtual function
<source>(6): error C2059: syntax error: 'constant'
<source>(7): error C2059: syntax error: 'constant'
I think we should aim for something like EDG's error. I don't care about the
order though.
I've updated the bug title to cover what's really wrong with GCC's diagnostics.