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 }; ^
*** Bug 29018 has been marked as a duplicate of this bug. ***
Mine.
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 ^
Fixed in r197742.