Bug 111526 - inconsistent handling of declaration after label
Summary: inconsistent handling of declaration after label
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2023-09-21 18:02 UTC by Pádraig Brady
Modified: 2023-09-21 18:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-09-21 00:00:00


Attachments
coreutils fix for non gcc >= 11 (650 bytes, text/plain)
2023-09-21 18:02 UTC, Pádraig Brady
Details
coreutils tail.c compilation unit (52.69 KB, text/plain)
2023-09-21 18:26 UTC, Pádraig Brady
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pádraig Brady 2023-09-21 18:02:35 UTC
Created attachment 55963 [details]
coreutils fix for non gcc >= 11

Ever since https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8b7a9a24
declarations after labels are allowed by default,
and only disabled with -pedantic etc.

I.e. the following simple code compiles on gcc >= 11,
but will fail when tried to be compiled with gcc <= 10, or clang for e.g.
This is exacerbated by the fact there is no compiler option
to avoid the issue on gcc <= 10 or clang,
as that code is explicitly disallowed by C11 and earlier.

    int f(int x) { switch (x) { case 1: int i=f(x); } return 0; }


There is also a more subtle related issue
(which I haven't fully reduced but can easily reproduce),
where the warning will NOT fire even with -Wpedantic on gcc 13 at least.
If one compiles GNU coreutils with the attached commit reverted,
and with -Wpedantic on newer gcc, it will _NOT_ issue a warning.
Comment 1 Andrew Pinski 2023-09-21 18:10:24 UTC
This is expected behavior.

 -Wc11-c2x-compat warns also ...


>(which I haven't fully reduced but can easily reproduce),


We need a testcase where you think it should warn but does not ...
Comment 2 Andrew Pinski 2023-09-21 18:13:50 UTC
Can you attach the original preprocessed source where you get no warning and you think you should. Others can reduce it.
Comment 3 Pádraig Brady 2023-09-21 18:26:40 UTC
Created attachment 55964 [details]
coreutils tail.c compilation unit

This should warn with -Wpedantic, but doesn't on gcc 13
Comment 4 Pádraig Brady 2023-09-21 18:28:11 UTC
Interestingly, gcc 13 _does_ warn with -Wc11-c2x-compat,
but does not warn with -Wpedantic
Comment 5 Andrew Pinski 2023-09-21 18:43:40 UTC
Hmm, somehow the value of warn_c11_c2x_compat is being changed from -1 to 0 ... and not being changed back, maybe a __extension__ is happening incorrectly.
Comment 6 Andrew Pinski 2023-09-21 18:45:11 UTC
Actually wait:
# 3997 "./lib/config.h"
#pragma GCC diagnostic ignored "-Wpedantic"

coreutils's config.h explictly disables -Wpedantic ...

So not a bug.