The spec grammar allows EnumBody to be just a semicolon, however a little further down it also says that enums must have at least one member.
This compiles however:
enum a;
Comment #1 by smjg — 2008-10-25T07:33:22Z
Either this is a contradiction in the spec, or we need clarification of what ';' as an EnumBody means.
Comment #2 by jlquinn — 2010-02-22T04:58:09Z
This would be fixed by changing the EnumBody rule to
EnumBody:
EnumMember ;
{ EnumMembers }
Comment #3 by smjg — 2010-02-22T08:07:25Z
So the meaning of that code changes from declaring an enum type with no members to declaring a manifest constant with value 0.
Comment #4 by jlquinn — 2010-02-26T05:29:58Z
(In reply to comment #3)
> So the meaning of that code changes from declaring an enum type with no members
> to declaring a manifest constant with value 0.
That seems more reasonable to me. However, if you specify a type as well, DMD rejects it:
enum long a;
enum1.d(1): Error: variable enum1.a manifest constants must have initializers
So at the moment it is inconsistent.
Comment #5 by jlquinn — 2010-02-26T05:35:27Z
I think the semicolon is intended to handle manifest constants. However, it doesn't look quite right.
If the grammar is rewritten as follows:
EnumDeclaration:
enum EnumBody
enum EnumTag EnumBody
enum : EnumBaseType EnumBody
enum EnumTag : EnumBaseType EnumBody
enum EnumMember ;
EnumBody:
{ EnumMembers }
Then manifest constants will be handled by the grammar, although the compiler enforces that they need an initializer.
Comment #6 by github-bugzilla — 2012-01-22T11:50:39Z