Hi, Tobias,

Sorry for the late reply (just came back from a long vacation after Cauldron).

And thank you for reporting this issue.

Please see my reply embedded below:

> On Sep 25, 2023, at 2:24 PM, Tobias Burnus <tob...@codesourcery.com> wrote:
> 
> Hi all,
> 
> I stumbled over this as I found the wording in the release notes rather 
> unclear.is.
> 
> 
> First, the following gives only a -pedantic warning and not a 
> -Wflex-array-member-not-at-end:
> 
>  struct t { int b; int x[]; };
>  struct q { int b; struct t a[2]; int c; };
> 
> warning: invalid use of structure with flexible array member [-Wpedantic]
> 
> If I remove the "[2]", it shows additionally:
>  warning: structure containing a flexible array member is not at the end of 
> another structure [-Wflex-array-member-not-at-end]

I think that the above behavior is correct as Richard mentioned previously.  -:)

First, by C99, a structure with flexible array member cannot be an element of 
an array, 
Therefore, struct t a[2] is an incorrect usage, the warning:

warning: invalid use of structure with flexible array member [-Wpedantic]

is complaining about this standard violation.  Though the diagnositic  message 
might need to be more specific like the following:

Warning: invalid use of structure with flexible array member as array element 
[-Wpedantic]

Then, after fixing this standard violation issue, the testing case is as 
following:

 struct t { int b; int x[]; };
 struct q { int b; struct t a; int c; };

adding -Wflex-array-member-not-at-end will report the expecting message:

/home/opc/Install/latest/bin/gcc -O  -Wflex-array-member-not-at-end t.c -S
t.c:2:29: warning: structure containing a flexible array member is not at the 
end of another structure [-Wflex-array-member-not-at-end]
    2 |  struct q { int b; struct t a; int c; };
      |                             ^

So, I think that GCC’s behavior is correct. 

However, we might need to make the diagnostic message more accurate here (I can 
submit a small patch to improve this). 

> 
> It seems as if it should print latter warning also inside the struct.
> 
> Qing? Joseph? Thoughts?
> 
> * * *
> 
> Secondly, if this is deprecated, shouldn't then the warning enabled by, e.g., 
> -Wall or made
> otherwise more prominent? (-std=?) - Currently, one either has to find the 
> new flag or use
> -pedantic.

Yes, agreed, However, I think that it might be better to delay this to next GCC 
release by giving users plenty time to fix all the 
-Wflex-array-member-not-at-end warnings.  As I know, linux kernel exposed a lot 
of warnings when adding -Wflex-array-member-not-at-end, and kernel people are 
trying to fix all these warnings in the source base.  

> 
> Or is this not really regarded as deprecated? But then (IMHO) we should not 
> really claim so and just
> add the warning without deprecation.

I think that our final goal is to deprecate this ambiguous extension from GCC 
completely, but we need time to mitigate users step by step. 
> 
> BTW; clang-15 prints the -Wgnu-variable-sized-type-not-at-end warning by 
> default.
> 
> Joseph, all: Thoughts?
> 
> * * *
> 
> Cross ref: The patch adding the new warning is r14-2197-g070a6bf0bdc6761
> https://gcc.gnu.org/pipermail/gcc-cvs/2023-June/385730.html (cf. previously 
> in this thread)
> 
> 
> * * *
> 
> Regarding the changes.html wording:
> 
> On 07.08.23 16:22, Qing Zhao via Gcc-patches wrote:
> 
>> Comparing to the 1st version, the only change is to address Richard's
>> comment on refering a warning option for diagnosing deprecated behavior.
> ...
>> +++ b/htdocs/gcc-14/changes.html
>> @@ -30,7 +30,18 @@ a work-in-progress.</p>
>>  <!-- .................................................................. -->
>>  <h2>Caveats</h2>
>>  <ul>
>> -  <li>...</li>
>> +  <li><strong>C:</strong>
>> +      Support for the GCC extension, a structure containing a C99 flexible 
>> array
>> +      member, or a union containing such a structure, is not the last field 
>> of
>> +      another structure, is deprecated. Refer to
>> +      <a href="https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html";>
>> +      Zero Length Arrays</a>.
> 
> ...
> 
> I find the first sentence difficult to read. What do you think of the 
> following?
> (It is hard to come up with some good wording.)
> 
> --- a/htdocs/gcc-14/changes.html
> +++ b/htdocs/gcc-14/changes.html
> @@ -31,9 +31,10 @@ a work-in-progress.</p>
> <h2>Caveats</h2>
> <ul>
>   <li><strong>C:</strong>
> -      Support for the GCC extension, a structure containing a C99 flexible 
> array
> -      member, or a union containing such a structure, is not the last field 
> of
> -      another structure, is deprecated. Refer to
> +      Support for the GCC extension that a structure containing a C99 
> flexible
> +      array (and any union containing a member of such structure) can be a
> +      member of a structure has been deprecated for the case that it is not
> +      the last member. Refer to
>       <a href="https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html";>
>       Zero Length Arrays</a>.
>       Any code relying on this extension should be modifed to ensure that

I  felt the above is more difficult to understand… how about below:

> +      Support for the GCC extension that a structure containing a C99 
> flexible
> +      array, or a union containing a member of such structure, is not the 
> last field 
> +      of another structure, has been deprecated. Refer to
> 

thanks.

Qing

> Tobias
> 
> PS:  C17 has:
> "A structure or union shall not contain a member with incomplete or function 
> type (hence, a structure
> shall not contain an instance of itself, but may contain a pointer to an 
> instance of itself), except that
> the last member of a structure with more than one named member may have 
> incomplete array type;
> such a structure (and any union containing, possibly recursively, a member 
> that is such a structure)
> shall not be a member of a structure or an element of an array."
> 
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
> München, HRB 106955

Reply via email to