Bug 54216 - Missing diagnostic for ill-formed anonymous enum declarations
Summary: Missing diagnostic for ill-formed anonymous enum declarations
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.1
: P3 minor
Target Milestone: 4.9.0
Assignee: Paolo Carlini
URL:
Keywords: accepts-invalid
: 29018 (view as bug list)
Depends on:
Blocks: 29843
  Show dependency treegraph
 
Reported: 2012-08-10 00:17 UTC by frankhb1989
Modified: 2021-08-04 22:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-04-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description frankhb1989 2012-08-10 00:17:37 UTC
G++(-pedantic-errors) wrongly accepts following non-conforming enumeration declarations(in namespace scope or block scope) and no diagnostic output at all:

enum {}; //-std=c++98 or -std=c++11

enum class {}; //-std=c++11

enum class { x }; //-std=c++11

According the standard, all of them are ill-formed:

(for the first declaration)
ISO C++98/03/11
7/3 ...
[Example:
enum { }; // ill-formed
typedef class { }; // ill-formed
β€”end example]

(for others)
ISO C++11
7.2/2 ... The optional identifier shall not be omitted in the declaration of a scoped enumeration. ...

While clang++(trunk, also using -pedantic-errors) rejects them correctly:

(for the first declaration, -std=c++98 or -std=c++11)
error: declaration does not declare anything
      [-Werror,-Wmissing-declarations]
enum {};
^~~~

(for others, -std=c++11)
error: scoped enumeration requires a name
enum class { };
           ^
error: declaration does not declare anything
      [-Werror,-Wmissing-declarations]
enum class { };
^~~~
error: scoped enumeration requires a name
enum class { x };
           ^
Comment 1 Paolo Carlini 2012-10-11 00:34:06 UTC
*** Bug 29018 has been marked as a duplicate of this bug. ***
Comment 2 Paolo Carlini 2013-04-10 00:36:11 UTC
Mine.
Comment 3 Paolo Carlini 2013-04-10 00:41:06 UTC
Hi Jason. I'm working on this and the patch is trivial but I suspect that quite a few testcases (in the library too) need adjusting. Thus, before I start to do that, wanted to ask: is it Ok a pedwarn for the first case:

enum {}; //-std=c++98 or -std=c++11

and an hard error for the other two:

enum class {}; //-std=c++11

enum class { x }; //-std=c++11

? Like:

54216.C:1:6: warning: anonymous enumeration may not be empty [-Wpedantic]
 enum {}; //-std=c++98 or -std=c++11
      ^
54216.C:3:12: error: scoped enumeration without a name
 enum class {}; //-std=c++11
            ^
54216.C:5:12: error: scoped enumeration without a name
 enum class { x }; //-std=c++11
            ^
Comment 4 Paolo Carlini 2013-04-11 09:04:55 UTC
Fixed in r197742.