[cfe-commits] r126243 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp test/Sema/MicrosoftExtensions.c test/SemaCXX/MicrosoftExtensions.cpp

Douglas Gregor dgregor at apple.com
Tue Feb 22 12:32:04 PST 2011


Author: dgregor
Date: Tue Feb 22 14:32:04 2011
New Revision: 126243

URL: http://llvm.org/viewvc/llvm-project?rev=126243&view=rev
Log:
Enable enumeration types with a fixed underlying type, e.g.,

  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.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=126243&r1=126242&r2=126243&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Feb 22 14:32:04 2011
@@ -59,6 +59,9 @@
   "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>;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=126243&r1=126242&r2=126243&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Feb 22 14:32:04 2011
@@ -1975,7 +1975,7 @@
     }
   }
 
-  bool AllowFixedUnderlyingType = getLang().CPlusPlus0x;
+  bool AllowFixedUnderlyingType = getLang().CPlusPlus0x || getLang().Microsoft;
   bool IsScopedEnum = false;
   bool IsScopedUsingClassTag = false;
 
@@ -2047,7 +2047,9 @@
         // 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 @@
     if (!PossibleBitfield) {
       SourceRange Range;
       BaseType = ParseTypeName(&Range);
+      
+      if (!getLang().CPlusPlus0x)
+        Diag(StartLoc, diag::ext_ms_enum_fixed_underlying_type)
+          << Range;
     }
   }
 

Modified: cfe/trunk/test/Sema/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftExtensions.c?rev=126243&r1=126242&r2=126243&view=diff
==============================================================================
--- cfe/trunk/test/Sema/MicrosoftExtensions.c (original)
+++ cfe/trunk/test/Sema/MicrosoftExtensions.c Tue Feb 22 14:32:04 2011
@@ -67,3 +67,15 @@
   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
+};

Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=126243&r1=126242&r2=126243&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Tue Feb 22 14:32:04 2011
@@ -109,3 +109,16 @@
   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
+};





More information about the cfe-commits mailing list