From: Richard Trieu Date: Tue, 23 Apr 2013 02:47:36 +0000 (+0000) Subject: Warn that scoped enumerations are a C++11 extenstion when compiling in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed5a292592c61f1b0d2da60dddea2fc11fb3f157;p=clang 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 '{' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180076 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index 277d2d7df4..4d9d42d258 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -688,6 +688,8 @@ def err_duplicate_virt_specifier : Error< def err_scoped_enum_missing_identifier : Error< "scoped enumeration requires a name">; +def ext_scoped_enum : ExtWarn< + "scoped enumerations are a C++11 extension">, InGroup; def warn_cxx98_compat_scoped_enum : Warning< "scoped enumerations are incompatible with C++98">, InGroup, DefaultIgnore; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 1215e36824..697e95a73e 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3367,9 +3367,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, bool IsScopedUsingClassTag = false; // In C++11, recognize 'enum class' and 'enum struct'. - if (getLangOpts().CPlusPlus11 && - (Tok.is(tok::kw_class) || Tok.is(tok::kw_struct))) { - Diag(Tok, diag::warn_cxx98_compat_scoped_enum); + if (Tok.is(tok::kw_class) || Tok.is(tok::kw_struct)) { + Diag(Tok, getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_scoped_enum + : diag::ext_scoped_enum); IsScopedUsingClassTag = Tok.is(tok::kw_class); ScopedEnumKWLoc = ConsumeToken(); diff --git a/test/SemaCXX/warn-c++11-extensions.cpp b/test/SemaCXX/warn-c++11-extensions.cpp index 8f35171119..bf8612aa39 100644 --- a/test/SemaCXX/warn-c++11-extensions.cpp +++ b/test/SemaCXX/warn-c++11-extensions.cpp @@ -5,3 +5,5 @@ long long ll1 = // expected-warning {{'long long' is a C++11 extension}} unsigned long long ull1 = // expected-warning {{'long long' is a C++11 extension}} 42ULL; // expected-warning {{'long long' is a C++11 extension}} +enum struct E1 { A, B }; // expected-warning {{scoped enumerations are a C++11 extension}} +enum class E2 { C, D }; // expected-warning {{scoped enumerations are a C++11 extension}}