[cfe-commits] r116704 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/MicrosoftExtensions.c test/SemaCXX/MicrosoftExtensions.cpp

Francois Pichet pichet2000 at gmail.com
Mon Oct 18 08:01:13 PDT 2010


Author: fpichet
Date: Mon Oct 18 10:01:13 2010
New Revision: 116704

URL: http://llvm.org/viewvc/llvm-project?rev=116704&view=rev
Log:
Microsoft enum extensions. 2 things will change on -fms-extensions:
1. enum underlying type is int by default.
2. Error "enumerator value is not representable in the underlying type"is a ExtWarning

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/MicrosoftExtensions.c
    cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=116704&r1=116703&r2=116704&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 18 10:01:13 2010
@@ -839,6 +839,9 @@
   "non-integral type %0 is an invalid underlying type">;
 def err_enumerator_too_large : Error<
   "enumerator value is not representable in the underlying type %0">;
+def ext_enumerator_too_large : ExtWarn<
+  "enumerator value is not representable in the underlying type %0">,
+  InGroup<Microsoft>;
 def err_enumerator_wrapped : Error<
   "enumerator value %0 is not representable in the underlying type %1">;
 def err_enum_redeclare_type_mismatch : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=116704&r1=116703&r2=116704&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 18 10:01:13 2010
@@ -5526,7 +5526,9 @@
         // Recover by falling back to int.
         EnumUnderlying = Context.IntTy.getTypePtr();
       }
-    }
+    } else if (getLangOptions().Microsoft)
+      // Microsoft enums are always of int type.
+      EnumUnderlying = Context.IntTy.getTypePtr();
   }
 
   DeclContext *SearchDC = CurContext;
@@ -7080,10 +7082,14 @@
           // C++0x [dcl.enum]p5:
           //   ... if the initializing value of an enumerator cannot be
           //   represented by the underlying type, the program is ill-formed.
-          if (!isRepresentableIntegerValue(Context, EnumVal, EltTy))
-            Diag(IdLoc, diag::err_enumerator_too_large)
-              << EltTy;
-          else
+          if (!isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
+            if (getLangOptions().Microsoft) {
+              Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
+              ImpCastExprToType(Val, EltTy, CK_IntegralCast);
+            } else 
+              Diag(IdLoc, diag::err_enumerator_too_large)
+                << EltTy;
+          } else
             ImpCastExprToType(Val, EltTy, CK_IntegralCast);
         }
         else {

Modified: cfe/trunk/test/Sema/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftExtensions.c?rev=116704&r1=116703&r2=116704&view=diff
==============================================================================
--- cfe/trunk/test/Sema/MicrosoftExtensions.c (original)
+++ cfe/trunk/test/Sema/MicrosoftExtensions.c Mon Oct 18 10:01:13 2010
@@ -19,3 +19,15 @@
    int l;
    int D[];
 };
+
+
+enum ENUM1; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}    
+enum ENUM1 var1 = 3;
+enum ENUM1* var2 = 0;
+
+
+enum ENUM2 {
+	ENUM2_a = (enum ENUM2) 4,
+	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
+	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
+};

Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=116704&r1=116703&r2=116704&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Mon Oct 18 10:01:13 2010
@@ -87,4 +87,13 @@
 
 //MSVC allows forward enum declaration
 enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
-ENUM *var;     
+ENUM *var = 0;     
+ENUM var2 = (ENUM)3;
+enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
+
+
+enum ENUM2 {
+	ENUM2_a = (enum ENUM2) 4,
+	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
+	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
+};





More information about the cfe-commits mailing list