Skip to content

Commit d0d87b5

Browse files
committed
Warn that scoped enumerations are a C++11 extenstion when compiling in
C++98 mode. This improves on the previous diagnostic message of: error: expected identifier or '{' llvm-svn: 180076
1 parent 7467f06 commit d0d87b5

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ def err_duplicate_virt_specifier : Error<
688688

689689
def err_scoped_enum_missing_identifier : Error<
690690
"scoped enumeration requires a name">;
691+
def ext_scoped_enum : ExtWarn<
692+
"scoped enumerations are a C++11 extension">, InGroup<CXX11>;
691693
def warn_cxx98_compat_scoped_enum : Warning<
692694
"scoped enumerations are incompatible with C++98">,
693695
InGroup<CXX98Compat>, DefaultIgnore;

clang/lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,9 +3367,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
33673367
bool IsScopedUsingClassTag = false;
33683368

33693369
// In C++11, recognize 'enum class' and 'enum struct'.
3370-
if (getLangOpts().CPlusPlus11 &&
3371-
(Tok.is(tok::kw_class) || Tok.is(tok::kw_struct))) {
3372-
Diag(Tok, diag::warn_cxx98_compat_scoped_enum);
3370+
if (Tok.is(tok::kw_class) || Tok.is(tok::kw_struct)) {
3371+
Diag(Tok, getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_scoped_enum
3372+
: diag::ext_scoped_enum);
33733373
IsScopedUsingClassTag = Tok.is(tok::kw_class);
33743374
ScopedEnumKWLoc = ConsumeToken();
33753375

clang/test/SemaCXX/warn-c++11-extensions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ long long ll1 = // expected-warning {{'long long' is a C++11 extension}}
55
unsigned long long ull1 = // expected-warning {{'long long' is a C++11 extension}}
66
42ULL; // expected-warning {{'long long' is a C++11 extension}}
77

8+
enum struct E1 { A, B }; // expected-warning {{scoped enumerations are a C++11 extension}}
9+
enum class E2 { C, D }; // expected-warning {{scoped enumerations are a C++11 extension}}

0 commit comments

Comments
 (0)