]> granicus.if.org Git - clang/commitdiff
Enable enumeration types with a fixed underlying type, e.g.,
authorDouglas Gregor <dgregor@apple.com>
Tue, 22 Feb 2011 20:32:04 +0000 (20:32 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 22 Feb 2011 20:32:04 +0000 (20:32 +0000)
  enum X : long { Value = 0x100000000 };

when in Microsoft-extension mode (-fms-extensions). This (now C++0x)
feature has been supported since Microsoft Visual Studio .NET 2003.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126243 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
test/Sema/MicrosoftExtensions.c
test/SemaCXX/MicrosoftExtensions.cpp

index fd64e90d739dc06e744d5c84c10c174936e5d1b2..7e20d20cd2338b442ee8aba44ea006efc275df98 100644 (file)
@@ -59,6 +59,9 @@ def err_enumerator_list_missing_comma : Error<
   "missing ',' between enumerators">;
 def err_enumerator_unnamed_no_def : Error<
   "unnamed enumeration must be a definition">;
+def ext_ms_enum_fixed_underlying_type : Extension<
+  "enumeration types with a fixed underlying type are a Microsoft extension">, 
+  InGroup<Microsoft>;
 
 def ext_gnu_indirect_goto : Extension<
   "use of GNU indirect-goto extension">, InGroup<GNU>;
index d9c5069f5988a500176aeecc709067795fefef6d..2999fdf5d4b3f212e982c6d6ba423b20e6ec6b35 100644 (file)
@@ -1975,7 +1975,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
     }
   }
 
-  bool AllowFixedUnderlyingType = getLang().CPlusPlus0x;
+  bool AllowFixedUnderlyingType = getLang().CPlusPlus0x || getLang().Microsoft;
   bool IsScopedEnum = false;
   bool IsScopedUsingClassTag = false;
 
@@ -2047,7 +2047,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
         // Consume the ':'.
         ConsumeToken();
       
-        if (isCXXDeclarationSpecifier() != TPResult::True()) {
+        if ((getLang().CPlusPlus && 
+             isCXXDeclarationSpecifier() != TPResult::True()) ||
+            (!getLang().CPlusPlus && !isDeclarationSpecifier(true))) {
           // We'll parse this as a bitfield later.
           PossibleBitfield = true;
           TPA.Revert();
@@ -2064,6 +2066,10 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
     if (!PossibleBitfield) {
       SourceRange Range;
       BaseType = ParseTypeName(&Range);
+      
+      if (!getLang().CPlusPlus0x)
+        Diag(StartLoc, diag::ext_ms_enum_fixed_underlying_type)
+          << Range;
     }
   }
 
index 0ef72855684d9d7789b57606e861159d5604b5a1..59bf54eb62fe56ad7c643df5626d4605c08f2416 100644 (file)
@@ -67,3 +67,15 @@ void foo()
   var.bad2;   // expected-error {{no member named 'bad2' in 'struct test'}}
 }
 
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
+
+struct X0 {
+  enum E1 : Int { SomeOtherValue } field;  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
+  enum E1 : seventeen;
+};
+
+enum : long {  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
+  SomeValue = 0x100000000
+};
index 2bcbbcaeb52d97dbc1859d62cde1d7a4e8b892a6..3592e2760aec7273869e24acad698d2d5c5081c5 100644 (file)
@@ -109,3 +109,16 @@ int main()
   f(0xffffffffffffffffLL);
   f(0xffffffffffffffffi64);
 }
+
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
+
+struct X0 {
+  enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
+  enum E1 : seventeen;
+};
+
+enum : long {  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
+  SomeValue = 0x100000000
+};