[Bug c++/81234] [6 Regression] stray notes for a flexible array member not at end of struct
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 27 19:26:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81234
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|rejects-valid |diagnostic
Known to work|6.3.1 |7.1.0, 8.0
Version|7.1.1 |6.3.1
Summary|[7/8 Regression] flexible |[6 Regression] stray notes
|array member not at end of |for a flexible array member
|‘struct |not at end of struct
Known to fail|7.1.0, 8.0 |6.3.1
Severity|normal |minor
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The C constraint is that a flexible array member must be the last member of a
struct. In addition, such a struct may not not be used to define a member in
another struct (not even as the last member). These constraints prevent
aliasing between such a member and those that follow.
In C, mode GCC accepts the test case from comment #0 but with -Wpedantic issues
a warning:
t.c:8:14: warning: invalid use of structure with flexible array member
[-Wpedantic]
G++ 7 is intentionally more strict here and rejects the code (the checking was
tightened up in r241143). The stray notes in GCC 6 (without -Wpedantic) are a
6.3 regression.
To avoid the error (and accept the risks of the array aliasing with members
stored at the same address) define data as a zero-length array
(https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html).
More information about the Gcc-bugs
mailing list