On Tue, 25 Nov 2025, Qing Zhao wrote:
> @@ -10001,8 +10014,10 @@ finish_struct (location_t loc, tree t, tree
> fieldlist, tree attributes,
> struct_parse_info->struct_types.safe_push (t);
> }
>
> - if (fields_with_counted_by.length () > 0)
> - verify_counted_by_attribute (t, &fields_with_counted_by);
> + /* Only when the enclosing struct/union type is not anonymous, do more
> + verification on the fields with counted_by attributes. */
> + if (c_type_tag (t) != NULL_TREE && C_TYPE_FIELDS_HAS_COUNTED_BY (t))
> + verify_counted_by_attribute (t, t);
I'm not convinced by this in the cases where a struct or union type with
no tag needs to be checked because it can be used for objects on its own
rather than only having its members accessed as if they were part of the
containing structure or union.
That is, examples like these should give errors. If these appear in the
testsuite somewhere to demonstrate that they do get diagnosed, could you
give details of where such cases are tested and how the verification gets
called for them in the compiler?
struct { char *p __attribute__ ((counted_by (n))); } x;
struct s { struct { char *p __attribute__ ((counted_by (n))); } *x; };
--
Joseph S. Myers
[email protected]