This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/81234] [6 Regression] stray notes for a flexible array member not at end of struct


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).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]