@(12);
Error: declaration expected following attribute, not `;`
But according to the grammar, EmtypDeclaration is a "declaration"
Comment #1 by razvan.nitu1305 — 2021-12-07T10:06:00Z
There is no such thing as an EmptyDeclaration in D. We do have empty statements, which are an entirely different thing. UDAs can be attached to declarations so it makes no sense to attach an UDA to a statement. Closing as invalid.
Comment #2 by stanislav.blinov — 2021-12-07T10:56:03Z
Comment #3 by razvan.nitu1305 — 2021-12-07T12:47:06Z
Ok, I was hasty in my judgement, however, I think that empty declarations are there just to have symmetry with empty statements (as you cannot have statements at top level), still I don't see any point in allowing attaching a UDA to an empty declaration.
To be more precise, UDA's are attached to symbols (that are indeed introduced by declarations). As far as I could tell you cannot attach a UDA to an anonymous function or an anonymous class, specifically because it does not have a name.
I guess we can modify the spec to specifically mention that UDAs must be applied to a symbol.
Comment #4 by rumbu — 2021-12-07T16:27:08Z
UDAs can be attached to any declaration according to the grammar, not to a symbol only.
How useful is that, it's debatable, but there are situations where the fact that attributes are attached to declarations, not to a symbol makes a huge difference:
@attr
int a, b, c;
where @attr is applied to a, b and c, not to a only.
Also there is the unittest case where there is no symbol, but attributes can have a meaning and can be obtained using __traits, see https://dlang.org/spec/traits.html#getUnitTests
There are two options:
- dmd must eat his own food by implementing the existing grammar specification or,
- the grammar must be adjusted to match the current situation;
Tizule, iute ești mă la mânie, ia-o mai ușor :)
Comment #5 by razvan.nitu1305 — 2021-12-09T09:27:29Z
(In reply to Răzvan Ștefănescu from comment #4)
> UDAs can be attached to any declaration according to the grammar, not to a
> symbol only.
>
> How useful is that, it's debatable, but there are situations where the fact
> that attributes are attached to declarations, not to a symbol makes a huge
> difference:
>
> @attr
> int a, b, c;
>
> where @attr is applied to a, b and c, not to a only.
>
Yes, but the point is that @attr is applied individually to each of the variable declarations.
> Also there is the unittest case where there is no symbol, but attributes can
> have a meaning and can be obtained using __traits, see
> https://dlang.org/spec/traits.html#getUnitTests
>
Unittests appear to not have a name, but they are actually not any different from any other function (internally, the compiler assigns a name of the form `__unittest_$generate_some_number`).
> There are two options:
> - dmd must eat his own food by implementing the existing grammar
> specification or,
> - the grammar must be adjusted to match the current situation;
>
I would opt for the later.
> Tizule, iute ești mă la mânie, ia-o mai ușor :)
:))
Comment #6 by robert.schadek — 2024-12-13T19:19:32Z