public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11
@ 2022-09-13 14:33 sigmaepsilon92 at gmail dot com
2022-09-13 14:39 ` [Bug c/106929] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: sigmaepsilon92 at gmail dot com @ 2022-09-13 14:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106929
Bug ID: 106929
Summary: declaration in switch-case doesn't fail since GCC 11
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sigmaepsilon92 at gmail dot com
Target Milestone: ---
this code should fail because declarations inside switch-cases aren't allowed
without {}:
void fn(int a) {
switch (a) {
case 0:
int c = 5;
break;
}
}
Starting with gcc 11 this doesn't fail to compile anymore though.
The expected error message would look like this:
<source>: In function 'fn':
<source>:4:13: error: a label can only be part of a statement and a declaration
is not a statement
4 | int c = 5;
| ^~~
Compiler returned: 1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/106929] declaration in switch-case doesn't fail since GCC 11
2022-09-13 14:33 [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11 sigmaepsilon92 at gmail dot com
@ 2022-09-13 14:39 ` redi at gcc dot gnu.org
2022-09-13 14:40 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-13 14:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106929
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This changed with r11-4813 and is intentional:
C Parser: Implement mixing of labels and code.
Implement mixing of labels and code as adopted for C2X
and process some std-attributes on labels.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/106929] declaration in switch-case doesn't fail since GCC 11
2022-09-13 14:33 [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11 sigmaepsilon92 at gmail dot com
2022-09-13 14:39 ` [Bug c/106929] " redi at gcc dot gnu.org
@ 2022-09-13 14:40 ` redi at gcc dot gnu.org
2022-09-13 14:42 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-13 14:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106929
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For C17 (and previous standards), if you use -pedantic you'll get a warning,
and -pedantic-errors will make it an error.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/106929] declaration in switch-case doesn't fail since GCC 11
2022-09-13 14:33 [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11 sigmaepsilon92 at gmail dot com
2022-09-13 14:39 ` [Bug c/106929] " redi at gcc dot gnu.org
2022-09-13 14:40 ` redi at gcc dot gnu.org
@ 2022-09-13 14:42 ` redi at gcc dot gnu.org
2022-09-13 14:44 ` sigmaepsilon92 at gmail dot com
2022-09-13 14:46 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-13 14:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106929
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's also the documented behaviour:
https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/Mixed-Labels-and-Declarations.html
and in the release notes:
https://gcc.gnu.org/gcc-11/changes.html#c
So not a bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/106929] declaration in switch-case doesn't fail since GCC 11
2022-09-13 14:33 [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11 sigmaepsilon92 at gmail dot com
` (2 preceding siblings ...)
2022-09-13 14:42 ` redi at gcc dot gnu.org
@ 2022-09-13 14:44 ` sigmaepsilon92 at gmail dot com
2022-09-13 14:46 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: sigmaepsilon92 at gmail dot com @ 2022-09-13 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106929
--- Comment #4 from Michael Zimmermann <sigmaepsilon92 at gmail dot com> ---
Interesting, but IMO it should still fail if you specify an older C standard
e.g. using `-std=c89`, but currently it doesn't.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/106929] declaration in switch-case doesn't fail since GCC 11
2022-09-13 14:33 [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11 sigmaepsilon92 at gmail dot com
` (3 preceding siblings ...)
2022-09-13 14:44 ` sigmaepsilon92 at gmail dot com
@ 2022-09-13 14:46 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-09-13 14:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106929
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
-std=c89 doesn't mean there aren't any extensions accepted, if you want the
compiler to be pedantic, -pedantic or -pedantic-errors are the options to use
as documented (the former just warns, the latter errors).
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-09-13 14:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 14:33 [Bug c/106929] New: declaration in switch-case doesn't fail since GCC 11 sigmaepsilon92 at gmail dot com
2022-09-13 14:39 ` [Bug c/106929] " redi at gcc dot gnu.org
2022-09-13 14:40 ` redi at gcc dot gnu.org
2022-09-13 14:42 ` redi at gcc dot gnu.org
2022-09-13 14:44 ` sigmaepsilon92 at gmail dot com
2022-09-13 14:46 ` jakub 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).