Bug 13361 – Empty UDA accepted

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-22T21:54:00Z
Last change time
2014-08-30T21:53:28Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
blah38621

Comments

Comment #0 by blah38621 — 2014-08-22T21:54:34Z
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.
Comment #4 by k.hara.pg — 2014-08-30T03:55:22Z
Comment #5 by github-bugzilla — 2014-08-30T21:53:28Z