D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2351 - enum with no members allowed
Summary: enum with no members allowed
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL: http://digitalmars.com/d/2.0/enum.html
Keywords: accepts-invalid, spec
Depends on:
Blocks:
 
Reported: 2008-09-10 04:46 UTC by Tomas Lindquist Olsen
Modified: 2014-02-15 13:12 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomas Lindquist Olsen 2008-09-10 04:46:42 UTC
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 Stewart Gordon 2008-10-25 07:33:22 UTC
Either this is a contradiction in the spec, or we need clarification of what ';' as an EnumBody means.
Comment 2 Jerry Quinn 2010-02-22 04:58:09 UTC
This would be fixed by changing the EnumBody rule to

EnumBody:
  EnumMember ;
  { EnumMembers }
Comment 3 Stewart Gordon 2010-02-22 08:07:25 UTC
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 Jerry Quinn 2010-02-26 05:29:58 UTC
(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 Jerry Quinn 2010-02-26 05:35:27 UTC
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.