On Wed, 11 Jun 2025, Qing Zhao wrote:

> Then how about the following case:
> 
> typedef struct item3 Item3;
> struct pointer_array_9 {
>   
>   int count3;
>   Item3 *array_3 __attribute__ ((counted_by (count3)));
> }
> 
> struct item3 {
>   int a;
>   float b[];
> }
> 
> In the above, the “Item3” is an incomplete type inside “struct 
> pointer_array_9”, whose definition is given
> afterward. 
> 
> Theoretically, C FE should issue error for the above counted_by attribute. 
> However, when and how should we
> Implement this in C FE:
> 
> when we examine the counted_by attribute for “array_3” inside “struct 
> pointer_array_9”, there is no any information
> on the TYPE of “Item3” yet, only when we see the definition of “struct item3” 
> afterward, we know that this structure
> includes a FAM, the previous “counted_by” attribute should not be added for 
> “array_3”. 
> 
> Is there a way to trace back to “struct pointer_array_9” when the definition 
> of “struct item3” is parsed? 
> When should we issue error for such case?

In general I think we'd only expect an error if the information required 
to give it is visible at the point where the counted_by attribute is used.  
There might be a possibility of giving an error for this case when the 
pointer gets dereferenced (and thus the counted_by information gets 
implicitly used).

-- 
Joseph S. Myers
josmy...@redhat.com

Reply via email to