> On Mar 27, 2023, at 12:06 PM, Jakub Jelinek <[email protected]> wrote:
>
> On Mon, Mar 27, 2023 at 03:57:58PM +0000, Qing Zhao wrote:
>>>> +Please use warning option @option{-Wgnu-variable-sized-type-not-at-end}
>>>> to
>>> This is certainly misnamed.
>>
>> The name “-Wgnu-variable-sized-type-not-at-end” was just used the warning
>> name from CLANG. -:)
>>
>> Shall we use the same name as CLANG? Or we invent a new name?
>
> The latter IMHO. Having a warning with completely nonsensical name will
> just confuse users.
Okay. -:)
How about "-Wstruct-with-fam-not-at-end”? Or do you have any suggestion on the
name?
>
>>> GNU variable sized type not at the end of a
>>> struct is something like
>>> void bar (void *);
>>> void foo (int n) {
>>> struct S { int a; int b[n]; int c; } s;
>>> s.a = 1;
>>> __builtin_memset (s.b, 0, sizeof (s.b));
>>> s.c = 3;
>>> bar (&s);
>>> }
>>> Certainly not flexible array members in the middle of structure.
>>
>> Right now, with -Wpedantic, we have the following warning for the above
>> small case:
>>
>> t2.c:3:24: warning: a member of a structure or union cannot have a variably
>> modified type [-Wpedantic]
>> 3 | struct S { int a; int b[n]; int c; } s;
>> | ^
>
> Sure, it is a GNU C extension (not allowed in C++ BTW).
> It is documented in https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
> though just very briefly:
> As an extension, GCC accepts variable-length arrays as a member of a
> structure or a union. For example:
> void
> foo (int n)
> {
> struct S { int x[n]; };
> }
Okay, I see.
>
>> Do we have a definition for “GNU variable sized type” now?
>
> Naturally, variable sized type should have non-constant sizeof, because
> otherwise it is constant sized type.
Oh, for flexible array members, we cannot take sizeof it, So they are
considered as incomplete type, right?
thanks.
Qing
> That is not
> the case for flexible array members, there is nothing variable sized on
> them, especially if they are in the middle of a structure.
>
> Jakub
>