DaveBartolomeo created this revision.
DaveBartolomeo added reviewers: rnk, cfe-commits.

When compiling as C targeting the MS ABI, but with -fno-ms-compatibility, an 
enumerator initializer that is not representable as an int is treated as an 
error. This is correct according to the C standard, but Clang already treats it 
as an extension both in -fms-compatibility mode and when compiling as C for 
non-MS ABI targets. It seemed odd that it would be treated as a hard error only 
in this one particular configuration, so I relaxed it to be an extension when 
targeting the MS ABI, regardless of MS compatibility mode.

There are dozens of occurrences of this issue in Windows SDK headers. By 
treating it as an extension, Clang users can include <windows.h> in a C program 
without having to use -fms-compatibility.


http://reviews.llvm.org/D22273

Files:
  lib/Sema/SemaDecl.cpp

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14351,7 +14351,13 @@
           // we perform a non-narrowing conversion as part of converted 
constant
           // expression checking.
           if (!isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
-            if (getLangOpts().MSVCCompat) {
+            if (getLangOpts().MSVCCompat ||
+                Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+              // Treat as an extension in MSVC compat mode or if using the
+              // MSVC ABI. We already treat the equivalent case in C as an
+              // extension if we're not in Microsoft mode. Several Windows
+              // headers define enums with initializers like 0x80000000 and
+              // 0xffffffff.
               Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
               Val = ImpCastExprToType(Val, EltTy, CK_IntegralCast).get();
             } else


Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14351,7 +14351,13 @@
           // we perform a non-narrowing conversion as part of converted constant
           // expression checking.
           if (!isRepresentableIntegerValue(Context, EnumVal, EltTy)) {
-            if (getLangOpts().MSVCCompat) {
+            if (getLangOpts().MSVCCompat ||
+                Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+              // Treat as an extension in MSVC compat mode or if using the
+              // MSVC ABI. We already treat the equivalent case in C as an
+              // extension if we're not in Microsoft mode. Several Windows
+              // headers define enums with initializers like 0x80000000 and
+              // 0xffffffff.
               Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
               Val = ImpCastExprToType(Val, EltTy, CK_IntegralCast).get();
             } else
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to