r343360 - Support enums with a fixed underlying type in all language modes.
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 28 13:24:58 PDT 2018
Author: epilk
Date: Fri Sep 28 13:24:58 2018
New Revision: 343360
URL: http://llvm.org/viewvc/llvm-project?rev=343360&view=rev
Log:
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
Added:
cfe/trunk/test/Sema/fixed-enum.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/Features.def
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/SemaObjC/enum-fixed-type.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=343360&r1=343359&r2=343360&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Sep 28 13:24:58 2018
@@ -88,9 +88,12 @@ def err_enumerator_unnamed_no_def : Erro
def ext_cxx11_enum_fixed_underlying_type : Extension<
"enumeration types with a fixed underlying type are a C++11 extension">,
InGroup<CXX11>;
-def ext_c_enum_fixed_underlying_type : Extension<
+def ext_ms_c_enum_fixed_underlying_type : Extension<
"enumeration types with a fixed underlying type are a Microsoft extension">,
InGroup<MicrosoftFixedEnum>;
+def ext_clang_c_enum_fixed_underlying_type : Extension<
+ "enumeration types with a fixed underlying type are a Clang extension">,
+ InGroup<DiagGroup<"fixed-enum-extension">>;
def warn_cxx98_compat_enum_fixed_underlying_type : Warning<
"enumeration types with a fixed underlying type are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
Modified: cfe/trunk/include/clang/Basic/Features.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Features.def?rev=343360&r1=343359&r2=343360&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Features.def (original)
+++ cfe/trunk/include/clang/Basic/Features.def Fri Sep 28 13:24:58 2018
@@ -89,7 +89,7 @@ FEATURE(objc_arc, LangOpts.ObjCAutoRefCo
FEATURE(objc_arc_fields, true)
FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
FEATURE(objc_default_synthesize_properties, LangOpts.ObjC2)
-FEATURE(objc_fixed_enum, LangOpts.ObjC2)
+FEATURE(objc_fixed_enum, true)
FEATURE(objc_instancetype, LangOpts.ObjC2)
FEATURE(objc_kindof, LangOpts.ObjC2)
FEATURE(objc_modules, LangOpts.ObjC2 &&LangOpts.Modules)
@@ -232,6 +232,7 @@ EXTENSION(cxx_range_for, LangOpts.CPlusP
EXTENSION(cxx_reference_qualified_functions, LangOpts.CPlusPlus)
EXTENSION(cxx_rvalue_references, LangOpts.CPlusPlus)
EXTENSION(cxx_variadic_templates, LangOpts.CPlusPlus)
+EXTENSION(cxx_fixed_enum, true)
// C++14 features supported by other languages as extensions.
EXTENSION(cxx_binary_literals, true)
EXTENSION(cxx_init_captures, LangOpts.CPlusPlus11)
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=343360&r1=343359&r2=343360&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Sep 28 13:24:58 2018
@@ -4153,15 +4153,11 @@ void Parser::ParseEnumSpecifier(SourceLo
// 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(SourceLo
// 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(SourceLo
// 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(SourceLo
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);
}
}
}
Added: cfe/trunk/test/Sema/fixed-enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/fixed-enum.c?rev=343360&view=auto
==============================================================================
--- cfe/trunk/test/Sema/fixed-enum.c (added)
+++ cfe/trunk/test/Sema/fixed-enum.c Fri Sep 28 13:24:58 2018
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -Weverything -xc++ -std=c++11 -DCXX11 -verify %s
+// RUN: %clang_cc1 -Weverything -xc++ -std=c++03 -DCXX03 -verify %s
+// RUN: %clang_cc1 -Weverything -xobjective-c -DOBJC -verify %s
+// RUN: %clang_cc1 -Weverything -std=c11 -xc -DC11 -verify %s
+// RUN: %clang_cc1 -Weverything -std=c11 -xc -fms-extensions -DMS -verify %s
+
+enum X : int {e};
+#if defined(CXX11)
+// expected-warning at -2{{enumeration types with a fixed underlying type are incompatible with C++98}}
+#elif defined(CXX03)
+// expected-warning at -4{{enumeration types with a fixed underlying type are a C++11 extension}}
+#elif defined(OBJC)
+// expected-no-diagnostics
+#elif defined(C11)
+// expected-warning at -8{{enumeration types with a fixed underlying type are a Clang extension}}
+#elif defined(MS)
+// expected-warning at -10{{enumeration types with a fixed underlying type are a Microsoft extension}}
+#endif
Modified: cfe/trunk/test/SemaObjC/enum-fixed-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/enum-fixed-type.m?rev=343360&r1=343359&r2=343360&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/enum-fixed-type.m (original)
+++ cfe/trunk/test/SemaObjC/enum-fixed-type.m Fri Sep 28 13:24:58 2018
@@ -1,9 +1,14 @@
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -xc %s
#if !__has_feature(objc_fixed_enum)
# error Enumerations with a fixed underlying type are not supported
#endif
+#if !__has_extension(cxx_fixed_enum)
+# error Enumerations with a fixed underlying type are not supported
+#endif
+
typedef long Integer;
typedef enum : Integer { Enumerator1, Enumerator2 } Enumeration;
More information about the cfe-commits
mailing list