On Tue, Jun 05, 2018 at 01:38:21PM +0200, Richard Biener wrote: > On Tue, Jun 5, 2018 at 1:39 AM Martin Sebor <mse...@gmail.com> wrote: > > > > GCC silently (without -Wpedantic) accepts declarations of zero > > length arrays that are followed by other members in the same > > struct, such as in: > > > > struct A { char a, b[0], c; }; > > > > Is it intended that accesses to elements of such arrays that > > alias other members be well-defined? > > The middle-end assumes that fields in a structure do not overlap. > For overlaps you have to use a union. > > In C++ I guess the rule that sizeof() of anything is at least 1 saves > you here so IMHO this is a C FE bug and we should probably simply > reject non-trailing empty arrays.
The above is not flexible array member, but zero sized array, that is just fine anywhere, at the toplevel as well as anywhere inside of the struct. And yes, accessing it out of bounds is invalid, unless it is flexible-like, i.e. at the end of the struct. Jakub