DMD currently accepts the following code, which is completely and utterly
useless:
struct A
{
@()
int b;
}
Comment #1 by k.hara.pg — 2014-08-28T09:32:21Z
But UDA can take zero-length tuple, which is finally reduced to @().
alias TypeTuple(T...) = T;
alias args = TypeTuple!(); // zero-length tuple
void foo() {}
@args void bar() {}
@() void baz() {}
pragma(msg, __traits(getAttributes, foo).length); // prints 0
pragma(msg, __traits(getAttributes, bar).length); // prints 0
pragma(msg, __traits(getAttributes, baz).length); // prints 0
Yes, it is useless, but I don't think it's invalid syntax.
Comment #2 by blah38621 — 2014-08-28T17:09:28Z
A zero length tuple at least means something, but an explicitly empty UDA
should be a syntax error. I believe that the only times it's possible for @()
to actually be in the code is accidental, and so the compiler should be helpful
in this case. @args should continue to be valid, and only @() should produce an
error.
Comment #3 by k.hara.pg — 2014-08-30T03:55:10Z
OK, I confirmed that current grammar does not allow empty argument list.
http://dlang.org/attribute.html#UserDefinedAttribute
UserDefinedAttribute:
@ ( ArgumentList ) // <--
@ Identifier
@ Identifier ( ArgumentList_opt )
ArgumentList is not optional, it should have one or more arguments.