On Mon, Jul 28, 2025 at 4:29 PM Martin Uecker <ma.uec...@gmail.com> wrote:
> Am Montag, dem 28.07.2025 um 16:01 -0700 schrieb Bill Wendling:
> > On Mon, Jul 28, 2025 at 2:39 PM Martin Uecker <ma.uec...@gmail.com> wrote:
> > > Yes, forwards declarations are this simplest solution.
> > >
> > Forward declarations work until you get something complex. For
> > example, if we want to support substructure fields in the attribute,
> > you'd have to replicate the whole substructure's declaration in the
> > forward decl. That becomes unwieldy when the substructure is very big:
> >
> > struct foo {
> >     char *buf __counted_by_expr(struct bar { ... } sub; sub.a.b);
> >     struct bar {
> >         int x, y;
> >         struct baz {
> >             int b;
> >             /* 20 other elements */
> >         } a;
> >         unsigned b1 : 1;
> >         unsigned b2 : 4;
> >         unsigned : 8;
> >         unsigned b3 : 2;
> >         /* and on and on... */
> >     } sub;
> > };
>
> You could write it like this:
>
> struct bar {
>         int x, y;
>         struct baz {
>             int b;
>             /* 20 other elements */
>         } a;
>         unsigned b1 : 1;
>         unsigned b2 : 4;
>         unsigned : 8;
>         unsigned b3 : 2;
>         /* and on and on... */
> };
>
> struct foo {
>     char *buf __counted_by_expr(struct bar sub; sub.a.b);
>     struct bar sub;
> };

One could always rewrite software to fit some random feature, the
question is whether they're going to want to do that. Or even if it's
feasible to do so. The idea is to make this feature as easy to use as
possible to add to existing code. Both Clang and GCC have the ability
to delay parsing the attribute until the struct has finished parsing.
You've offered no argument against that except for some vague worries
about "context". While context is definitely important to parsing, the
expected expressions are a strictly defined subset of generalized
expressions. Parsing an affine equation doesn't require a ton of
context, except for resolved types in the case of delayed parsing.

-bw

Reply via email to