[PATCH] accept flexible arrays in struct in unions (c++/71912 - [6/7 regression])

Martin Sebor msebor@gmail.com
Wed Sep 14 17:05:00 GMT 2016


Attached is an updated patch that does away with the "overlapping"
warning and instead issues the same warnings as the C front end
(though with more context).

In struct flexmems_t I've retained the NEXT array even though only
the first element is used to diagnose problems.  The second element
is used by the find_flexarrays function to differentiate structs
with flexible array members in unions (which are valid) from those
in structs (which are not).

FWIW, I think this C restriction on structs is unnecessary and will
propose to remove it so that's valid to define a struct that contains
another struct (possibly recursively) with a flexible array member.
I.e., I think this should be made valid in C (and accepted without
the pedantic warning that GCC, and with this patch also G++, issues):

   struct X { int i, a[]; };
   struct S1 { struct X x; };
   struct S2 { struct S1 s1; };

z.C:2:22: warning: invalid use of ‘struct X’ with a flexible array 
member in ‘struct S1’ [-Wpedantic]
  struct S1 { struct X x; };
                       ^
z.C:1:21: note: array member ‘int X::a []’ declared here
  struct X { int i, a[]; };
                      ^
z.C:3:23: warning: invalid use of ‘struct X’ with a flexible array 
member in ‘struct S2’ [-Wpedantic]
  struct S2 { struct S1 s1; };
                        ^~
z.C:1:21: note: array member ‘int X::a []’ declared here
  struct X { int i, a[]; };
                      ^

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-71912.diff
Type: text/x-patch
Size: 38762 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160914/c0b0c688/attachment.bin>


More information about the Gcc-patches mailing list