On Fri, 16 Oct 2015, Bernd Schmidt wrote: > > + // The following expression is silently accepted as an extension > > + // because it simply forms the equivalent of a just-past-the-end > > + // address. > > + __builtin_offsetof (A, a1_1 [0][1]), // extension > > Hmm, do we really want to support any kind of multidimensional array for this > extension? My guess would have been to warn here.
We do deliberately want to support sequences of array indexing and structure / union member reference inside __builtin_offsetof. > So I checked and it looks like we accept flexible array member syntax like > "int a[][2];", which suggests that the test might have the right idea, but has > the indices swapped (the first one is the flexible one)? Ccing Joseph for a > ruling. "int a[][2];" is a fully valid flexible array member (whose elements have type int[2]) - ISO C, not an extension. Given such a flexible array member, [anything][0] and [anything][1] are logically valid if [anything] is nonnegative (of course, the array might or might not have enough element at runtime). [anything][2] is a reference to just past the end of an element of the flexible array member; [anything][3] is clearly invalid. Regarding the actual testcase, accepting a1_1[0][1] seems fine (it's referencing the just-past-end element of the valid array a1_1[0]). The test unfortunately doesn't show what happens in cases with fewer indices - it should be expanded that way. I'd say a1_1[1] should be accepted as just past end, even if a1_1[1][0] gets a warning as shown in the test. -- Joseph S. Myers jos...@codesourcery.com