diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2018-09-28 20:24:58 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2018-09-28 20:24:58 +0000 |
commit | 6f11db137034b38dbe2aabfa823ac0f2a7e3f9b9 (patch) | |
tree | 140a09f64fa370717a9b98bcdebb27d0fc62a8a5 /clang/lib/Parse/ParseDecl.cpp | |
parent | bb993be56bb38e46c029b682f67fd1b7dc4b9111 (diff) | |
download | llvm-6f11db137034b38dbe2aabfa823ac0f2a7e3f9b9.zip llvm-6f11db137034b38dbe2aabfa823ac0f2a7e3f9b9.tar.gz llvm-6f11db137034b38dbe2aabfa823ac0f2a7e3f9b9.tar.bz2 |
Support enums with a fixed underlying type in all language modes.
Previously we supported these in C++, ObjC, and C with -fms-extensions.
rdar://43831380
Differential revision: https://reviews.llvm.org/D52339
llvm-svn: 343360
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 4393c8a..bbcc860 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4153,15 +4153,11 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, // Enum definitions should not be parsed in a trailing-return-type. bool AllowDeclaration = DSC != DeclSpecContext::DSC_trailing; - bool AllowFixedUnderlyingType = AllowDeclaration && - (getLangOpts().CPlusPlus11 || getLangOpts().MicrosoftExt || - getLangOpts().ObjC2); - CXXScopeSpec &SS = DS.getTypeSpecScope(); if (getLangOpts().CPlusPlus) { // "enum foo : bar;" is not a potential typo for "enum foo::bar;" // if a fixed underlying type is allowed. - ColonProtectionRAIIObject X(*this, AllowFixedUnderlyingType); + ColonProtectionRAIIObject X(*this, AllowDeclaration); CXXScopeSpec Spec; if (ParseOptionalCXXScopeSpecifier(Spec, nullptr, @@ -4183,7 +4179,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, // Must have either 'enum name' or 'enum {...}'. if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) && - !(AllowFixedUnderlyingType && Tok.is(tok::colon))) { + !(AllowDeclaration && Tok.is(tok::colon))) { Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace; // Skip the rest of this declarator, up until the comma or semicolon. @@ -4216,7 +4212,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, // Parse the fixed underlying type. bool CanBeBitfield = getCurScope()->getFlags() & Scope::ClassScope; - if (AllowFixedUnderlyingType && Tok.is(tok::colon)) { + if (AllowDeclaration && Tok.is(tok::colon)) { bool PossibleBitfield = false; if (CanBeBitfield) { // If we're in class scope, this can either be an enum declaration with @@ -4276,13 +4272,15 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, SourceRange Range; BaseType = ParseTypeName(&Range); - if (getLangOpts().CPlusPlus11) { - Diag(StartLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type); - } else if (!getLangOpts().ObjC2) { - if (getLangOpts().CPlusPlus) - Diag(StartLoc, diag::ext_cxx11_enum_fixed_underlying_type) << Range; + if (!getLangOpts().ObjC2) { + if (getLangOpts().CPlusPlus11) + Diag(StartLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type); + else if (getLangOpts().CPlusPlus) + Diag(StartLoc, diag::ext_cxx11_enum_fixed_underlying_type); + else if (getLangOpts().MicrosoftExt) + Diag(StartLoc, diag::ext_ms_c_enum_fixed_underlying_type); else - Diag(StartLoc, diag::ext_c_enum_fixed_underlying_type) << Range; + Diag(StartLoc, diag::ext_clang_c_enum_fixed_underlying_type); } } } |