The c++ parser accepts: enum { }; which is specifically listed in clause 7 paragraph 3 of the C++ standard as ill-formed.
Confirmed, not a regression.
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 '}'. */
So, do we want to fix those testcases or do we want to keep ignoring empty enums?
I think we want to fix the test cases, but I don't want to sign up to fix them myself.
(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.
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).
On it.
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.
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).
Not actively working on it (for now)
Special case. *** This bug has been marked as a duplicate of bug 54216 ***