[PATCH] D22273: Treat enumerator_too_large as an extension in MS ABI mode

Dave Bartolomeo via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 12 12:15:36 PDT 2016

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.



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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22273.63707.patch
Type: text/x-patch
Size: 1036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160712/4a41e844/attachment.bin>

More information about the cfe-commits mailing list