Thread overview
[Issue 2351] New: enum with no members allowed
Sep 10, 2008
d-bugmail
Oct 25, 2008
d-bugmail
Feb 22, 2010
Jerry Quinn
Feb 22, 2010
Stewart Gordon
Feb 26, 2010
Jerry Quinn
Feb 26, 2010
Jerry Quinn
Jan 22, 2012
Walter Bright
September 10, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2351

           Summary: enum with no members allowed
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: tomas@famolsen.dk


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;


-- 

October 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2351


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Keywords|                            |spec




------- Comment #1 from smjg@iname.com  2008-10-25 07:33 -------
Either this is a contradiction in the spec, or we need clarification of what ';' as an EnumBody means.


-- 

February 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2351


Jerry Quinn <jlquinn@optonline.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://digitalmars.com/d/2.
                   |                            |0/enum.html
                 CC|                            |jlquinn@optonline.net


--- Comment #2 from Jerry Quinn <jlquinn@optonline.net> 2010-02-22 04:58:09 PST ---
This would be fixed by changing the EnumBody rule to

EnumBody:
  EnumMember ;
  { EnumMembers }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2351



--- Comment #3 from Stewart Gordon <smjg@iname.com> 2010-02-22 08:07:25 PST ---
So the meaning of that code changes from declaring an enum type with no members to declaring a manifest constant with value 0.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2351



--- Comment #4 from Jerry Quinn <jlquinn@optonline.net> 2010-02-26 05:29:58 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2351



--- Comment #5 from Jerry Quinn <jlquinn@optonline.net> 2010-02-26 05:35:27 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2351



--- Comment #6 from github-bugzilla@puremagic.com 2012-01-22 11:50:39 PST ---
Commit pushed to https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/31be563dc0bc4afaaf84c24deb527d60c3ec2e83 fix Issue 2351 - enum with no members allowed

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2351


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------