Bug 29018 - empty enum accepted
Summary: empty enum accepted
Status: RESOLVED DUPLICATE of bug 54216
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 29843
  Show dependency treegraph
 
Reported: 2006-09-11 16:02 UTC by Jorn Wolfgang Rennecke
Modified: 2012-10-11 00:34 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3, 3.0.4, 3.2.3, 3.3.3, 3.4.0, 4.1.0, 4.2.0, 4.7.0
Last reconfirmed: 2006-09-11 16:09:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2006-09-11 16:02:24 UTC
The c++ parser accepts:

enum { };

which is specifically listed in clause 7 paragraph 3 of the C++ standard as ill-formed.
Comment 1 Andrew Pinski 2006-09-11 16:09:24 UTC
Confirmed, not a regression.
Comment 2 Steve Ellcey 2006-09-15 16:46:36 UTC
I took a quick look at this bug, the fix is easy, I have included a patch I created.  The problem is that there are 172 tests in the g++ and libstdc++
test suites that have empty enums in them.  If we give an error on empty enums we will need to fix a lot of tests.

Patch:

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c     (revision 116960)
+++ gcc/cp/parser.c     (working copy)
@@ -10317,8 +10317,10 @@ cp_parser_enum_specifier (cp_parser* par
       return error_mark_node;
     }

-  /* If the next token is not '}', then there are some enumerators.  */
-  if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE))
+  /* An empty enum is not allowed.  */
+  if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
+    error ("an enum may not be empty");
+  else
     cp_parser_enumerator_list (parser, type);

   /* Consume the final '}'.  */
Comment 3 Manuel López-Ibáñez 2007-01-21 18:24:07 UTC
So, do we want to fix those testcases or do we want to keep ignoring empty enums?
Comment 4 Steve Ellcey 2007-01-24 00:34:06 UTC
I think we want to fix the test cases, but I don't want to sign up to fix them myself.
Comment 5 Manuel López-Ibáñez 2007-01-24 01:31:11 UTC
(In reply to comment #4)
> I think we want to fix the test cases, but I don't want to sign up to fix them
> myself.
> 

"I think" is not enough. It would be nice to be able tell to whoever takes the burden of implementing this that fixing the testcases is OK and that such patch will be approved (and give any hints about the better way to fix the testcases). Since this affects testcases for g++ and libstdc++, this may require approval from more than one maintainer.
Comment 6 Steve Ellcey 2007-01-24 16:05:37 UTC
Well, "I think" is all I can give.  I am not a maintainer who can approve a patch for this.  If you want to work on it I would recommend doing a patch that just involves a small subset of the test suite fixes and see if you can get the attention of someone who can approve such a patch.  Once some testsuite changes have been approved it will probably be easier to get the rest of the testsuite changes approved (maybe even preapproved).
Comment 7 Paolo Carlini 2007-09-04 16:51:59 UTC
On it.
Comment 8 Paolo Carlini 2007-09-04 17:47:06 UTC
Hummm, with reference to the patch in Comment #9: I don't think 'enum { };' is flagged in the standard as ill-formed because of the empty enumerator-list (that possibility is explicitly discussed in 7.2/5), but because the enum doesn't have a name. In other terms, the example is ill-formed for the very same reason anonymous structs are a GNU extension. In yet other terms, it seems to me we have got an anonymous enum extension, which probably we want to diagnose when pedantic.
Comment 9 Paolo Carlini 2007-09-04 17:53:11 UTC
Humm, no, anonymous enums are clearly legal, sorry about the stupid mistake. Still, it's not completely clear to me the discussion in 7.2/5 of empty enumerator-lists, evidently, we must assume those are illegal *only* when the enum is simultaneously anonymous (and the patch in Comment #2 is therefore incomplete, not completely wrong, sorry about the misunderstanding).
Comment 10 Paolo Carlini 2007-09-17 19:18:25 UTC
Not actively working on it (for now)
Comment 11 Paolo Carlini 2012-10-11 00:34:06 UTC
Special case.

*** This bug has been marked as a duplicate of bug 54216 ***