Based on all your comments so far, I changed the documentation as the following:
-The counted_by attribute is not allowed for a pointer field whose pointee
-has type @code{void}.
+The counted_by attribute is not allowed for a pointer to @code{void},
+a pointer to function, or a pointer to a structure or union that includes
+a flexible array member. However, it is allowed for a pointer to
+non-void incomplte structure or union types, as long as the type could
+be completed before the first dereference to the pointer.
And also updated the code and testing cases according to the above.
Let me know if I still miss anything.
Thanks a lot.
Qing
> On Jun 11, 2025, at 15:45, Joseph Myers <[email protected]> wrote:
>
> On Wed, 11 Jun 2025, Qing Zhao wrote:
>
>> When I was adding more testing cases for the pointee type being
>> structure/union, I have a question for the following case:
>>
>> struct item5 {
>> int a;
>> float b[];
>> };
>>
>> struct pointer_array_9 {
>> ...
>> int count5;
>> struct item5 *array_5 __attribute__ ((counted_by (count5)));
>> };
>>
>> In the above, “struct item5” is a structure type with flexible array
>> member, whose size is not know during compilation time, as a result, the
>> size of the whole structure is unknown during compilation time, shall we
>> reject such cases?
>
> Since the standard doesn't allow a structure with a flexible array member
> (or a union containing such a structure, recursively) to be an element of
> an array, it seems reasonable to reject such cases as well.
>
> --
> Joseph S. Myers
> [email protected]