public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113153] New: suboptimal error message when using reserved identifier
@ 2023-12-27 2:27 michael.kenzel at gmail dot com
2023-12-27 2:37 ` [Bug c++/113153] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: michael.kenzel at gmail dot com @ 2023-12-27 2:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113153
Bug ID: 113153
Summary: suboptimal error message when using reserved
identifier
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: michael.kenzel at gmail dot com
Target Milestone: ---
When using a keyword as the name of an enum, gcc will issue a diagnostic about
the enum being "unnamed". This can be very confusing:
enum class register { rax, rcx, rdx, rbx };
compiled with -std=c++23 produces
error: unnamed scoped enum is not allowed
1 | enum class register {};
| ^~~~~~~~
warning: elaborated-type-specifier for a scoped enum must not use the 'class'
keyword
1 | enum class register {};
| ~~~~ ^~~~~
| -----
error: expected identifier before 'register'
1 | enum class register {};
| ^~~~~~~~
error: expected unqualified-id before '{' token
1 | enum class register {};
| ^
https://godbolt.org/z/s1ocevaWe
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/113153] suboptimal error message when using reserved identifier
2023-12-27 2:27 [Bug c++/113153] New: suboptimal error message when using reserved identifier michael.kenzel at gmail dot com
@ 2023-12-27 2:37 ` pinskia at gcc dot gnu.org
2023-12-27 2:38 ` pinskia at gcc dot gnu.org
2023-12-27 2:49 ` [Bug c++/113153] suboptimal error message when using reserved identifier and `enum class` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27 2:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113153
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Note clang is just as bad:
```
<source>:1:16: error: expected identifier or '{'
1 | enum class register { rax, rcx, rdx, rbx };
| ^
1 error generated.
```
EDG/ICC is slightly better:
```
<source>(1): error: expected an identifier
enum class register { rax, rcx, rdx, rbx };
^
```
MSVC is bad too:
```
<source>(1): error C2332: 'enum': missing tag name
<source>(1): error C2059: syntax error: 'function-style cast'
<source>(1): error C2143: syntax error: missing ';' before '{'
<source>(1): error C2447: '{': missing function header (old-style formal list?)
```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/113153] suboptimal error message when using reserved identifier
2023-12-27 2:27 [Bug c++/113153] New: suboptimal error message when using reserved identifier michael.kenzel at gmail dot com
2023-12-27 2:37 ` [Bug c++/113153] " pinskia at gcc dot gnu.org
@ 2023-12-27 2:38 ` pinskia at gcc dot gnu.org
2023-12-27 2:49 ` [Bug c++/113153] suboptimal error message when using reserved identifier and `enum class` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27 2:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113153
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
If you remove the class, GCC has a decent error message:
```
<source>:1:11: error: expected identifier before 'register'
1 | enum register { rax, rcx, rdx, rbx };
| ^~~~~~~~
```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/113153] suboptimal error message when using reserved identifier and `enum class`
2023-12-27 2:27 [Bug c++/113153] New: suboptimal error message when using reserved identifier michael.kenzel at gmail dot com
2023-12-27 2:37 ` [Bug c++/113153] " pinskia at gcc dot gnu.org
2023-12-27 2:38 ` pinskia at gcc dot gnu.org
@ 2023-12-27 2:49 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27 2:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113153
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Summary|suboptimal error message |suboptimal error message
|when using reserved |when using reserved
|identifier |identifier and `enum class`
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-12-27
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-12-27 2:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 2:27 [Bug c++/113153] New: suboptimal error message when using reserved identifier michael.kenzel at gmail dot com
2023-12-27 2:37 ` [Bug c++/113153] " pinskia at gcc dot gnu.org
2023-12-27 2:38 ` pinskia at gcc dot gnu.org
2023-12-27 2:49 ` [Bug c++/113153] suboptimal error message when using reserved identifier and `enum class` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).