public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94428] New: Reintroduce -Wzero-length-array
@ 2020-04-01 7:23 kees at outflux dot net
2020-04-01 8:51 ` [Bug c/94428] " marxin at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kees at outflux dot net @ 2020-04-01 7:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94428
Bug ID: 94428
Summary: Reintroduce -Wzero-length-array
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: kees at outflux dot net
Target Milestone: ---
It would be nice to gain "-Wzero-length-array" so we can enforce this standard
in the Linux kernel once all conversions have moved struct to flexible array
members. Clang supports this as a distinct warning, but gcc currently only
warns about this under "-pedantic -std=c99", which is not a workable
combination for Linux. ;)
$ clang -Wzero-length-array -o bounds-clang bounds.c
bounds.c:20:15: warning: zero size arrays are an extension
[-Wzero-length-array]
char data[0];
^
$ gcc -Wzero-length-array -o bounds-gcc bounds.c
gcc: error: unrecognized command line option ‘-Wzero-length-array’
$ gcc -pedantic -std=c99 -o bounds-gcc bounds.c
bounds.c:20:10: warning: ISO C forbids zero-size array ‘data’ [-Wpedantic]
20 | char data[0];
| ^~~~
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/94428] Reintroduce -Wzero-length-array
2020-04-01 7:23 [Bug c/94428] New: Reintroduce -Wzero-length-array kees at outflux dot net
@ 2020-04-01 8:51 ` marxin at gcc dot gnu.org
2020-04-01 16:03 ` msebor at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-04-01 8:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94428
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-04-01
Ever confirmed|0 |1
CC| |jsm28 at gcc dot gnu.org,
| |marxin at gcc dot gnu.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/94428] Reintroduce -Wzero-length-array
2020-04-01 7:23 [Bug c/94428] New: Reintroduce -Wzero-length-array kees at outflux dot net
2020-04-01 8:51 ` [Bug c/94428] " marxin at gcc dot gnu.org
@ 2020-04-01 16:03 ` msebor at gcc dot gnu.org
2021-09-24 19:28 ` kees at outflux dot net
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-01 16:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94428
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
Keywords| |diagnostic
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
With the introduction of -Wzero-length-bounds in GCC 10 (which, incidentally,
was added specifically to ease the adoption of the stricter array bounds
checking in GCC 10 by the kernel), adding a knob to diagnose declarations of
zero-length arrays sounds like a good idea to me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/94428] Reintroduce -Wzero-length-array
2020-04-01 7:23 [Bug c/94428] New: Reintroduce -Wzero-length-array kees at outflux dot net
2020-04-01 8:51 ` [Bug c/94428] " marxin at gcc dot gnu.org
2020-04-01 16:03 ` msebor at gcc dot gnu.org
@ 2021-09-24 19:28 ` kees at outflux dot net
2021-09-24 21:59 ` segher at gcc dot gnu.org
2022-12-20 18:03 ` qinzhao at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: kees at outflux dot net @ 2021-09-24 19:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94428
--- Comment #2 from Kees Cook <kees at outflux dot net> ---
Note that this needs a struct attribute that will allow structs to be excluded
from the diagnostic (since the kernel needs to deal with legacy UAPI headers
forever).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/94428] Reintroduce -Wzero-length-array
2020-04-01 7:23 [Bug c/94428] New: Reintroduce -Wzero-length-array kees at outflux dot net
` (2 preceding siblings ...)
2021-09-24 19:28 ` kees at outflux dot net
@ 2021-09-24 21:59 ` segher at gcc dot gnu.org
2022-12-20 18:03 ` qinzhao at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: segher at gcc dot gnu.org @ 2021-09-24 21:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94428
--- Comment #3 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #1)
> With the introduction of -Wzero-length-bounds in GCC 10 (which,
> incidentally, was added specifically to ease the adoption of the stricter
> array bounds checking in GCC 10 by the kernel), adding a knob to diagnose
> declarations of zero-length arrays sounds like a good idea to me.
Should we warn about this by default even, for new enough C versions? So for
-std=c99 and later? What about even for -std=gnu99 and later?
Warning for arrays of length 1 is more dubious. If we really want that it
should be a separate option?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/94428] Reintroduce -Wzero-length-array
2020-04-01 7:23 [Bug c/94428] New: Reintroduce -Wzero-length-array kees at outflux dot net
` (3 preceding siblings ...)
2021-09-24 21:59 ` segher at gcc dot gnu.org
@ 2022-12-20 18:03 ` qinzhao at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-12-20 18:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94428
--- Comment #4 from qinzhao at gcc dot gnu.org ---
a new warning -Wstrict-flex-arrays was added to gcc13.
when using -Wstrict-flex-arrays -fstrict-flex-arrays=3 together, the new
warning will report any misuse of zero-length arrays as flexible array members.
I think this new warning could be a replacement of this -Wzero-length-array.
therefore the warning -Wzero-length-array might not be needed anymore.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-20 18:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01 7:23 [Bug c/94428] New: Reintroduce -Wzero-length-array kees at outflux dot net
2020-04-01 8:51 ` [Bug c/94428] " marxin at gcc dot gnu.org
2020-04-01 16:03 ` msebor at gcc dot gnu.org
2021-09-24 19:28 ` kees at outflux dot net
2021-09-24 21:59 ` segher at gcc dot gnu.org
2022-12-20 18:03 ` qinzhao 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).