https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92589
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> I thought GCC documented this differently. So this is just a documentation
> issue.
> GCC allows even non-1 sized fields to be considered flexible arrays if they
> are at the end of the struct.
GCC might handle it gracefully in many contexts but it's considered a bug (in
user code) and warnings like -Wstringop-overflow try to detect and diagnose it,
so it's something to avoid. At -O3, current trunk issues:
pr92589.c:41:27: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
41 | non_flex->data[i] = argv[1][i];
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
pr92589.c:14:10: note: destination object declared here
14 | char data[2];
| ^~~~
GCC manual (Zero Length Arrays) documents the [] and [0] forms and discourages
the [1] form of trailing arrays. There is no mention of arrays with more
elements being treated that way.