Bug 17606 – dmd wrongly accepts field without type when annotated with a UDA

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-05T18:51:00Z
Last change time
2017-07-07T06:08:46Z
Assigned to
nobody
Creator
timothee.cour2

Comments

Comment #0 by timothee.cour2 — 2017-07-05T18:51:24Z
DMD64 D Compiler v2.074.0 ``` struct foo{} struct A{ // compiles but shouldn't: missing bool @foo a=false; } ```
Comment #1 by ag0aep6g — 2017-07-05T19:21:31Z
As far as I can tell, the grammar allows it. As a UserDefinedAttribute, `@foo` matches Property [1]. Property is one of the options for StorageClass [2] (another option is the `auto` keyword). With `@foo` matching StorageClass, `@foo a = false;` matches AutoDeclaration [3] just like `auto a = false;` would. [1] http://dlang.org/spec/attribute.html#Property [2] http://dlang.org/spec/declaration.html#StorageClass [3] http://dlang.org/spec/declaration.html#AutoDeclaration
Comment #2 by dlang-bugzilla — 2017-07-07T05:57:48Z
Yeah, pretty sure you can add anything to a declaration that distinguishes it from a statement, which apparently includes UDAs. "auto" is a no-effect keyword that you can use if you have nothing else to write there. Same reason why `const foo() { return 1; }` is valid inside a method.