r239382 - [MSVC Compatibility] Don't diagnose c-style cast from void-ptr to fn-ptr

David Majnemer david.majnemer at gmail.com
Mon Jun 8 19:41:09 PDT 2015


Author: majnemer
Date: Mon Jun  8 21:41:08 2015
New Revision: 239382

URL: http://llvm.org/viewvc/llvm-project?rev=239382&view=rev
Log:
[MSVC Compatibility] Don't diagnose c-style cast from void-ptr to fn-ptr

The machinery added to permit a static_cast from void-ptr to fn-ptr
unintentionally gets triggered for c-style casts and function-style
casts.  The observable effect was a diagnostic issued inappropriately.

Modified:
    cfe/trunk/lib/Sema/SemaCast.cpp
    cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=239382&r1=239381&r2=239382&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Mon Jun  8 21:41:08 2015
@@ -1084,7 +1084,8 @@ static TryCastResult TryStaticCast(Sema
 
         // Microsoft permits static_cast from 'pointer-to-void' to
         // 'pointer-to-function'.
-        if (Self.getLangOpts().MSVCCompat && DestPointee->isFunctionType()) {
+        if (!CStyle && Self.getLangOpts().MSVCCompat &&
+            DestPointee->isFunctionType()) {
           Self.Diag(OpRange.getBegin(), diag::ext_ms_cast_fn_obj) << OpRange;
           Kind = CK_BitCast;
           return TC_Success;

Modified: cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp?rev=239382&r1=239381&r2=239382&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp Mon Jun  8 21:41:08 2015
@@ -7,4 +7,8 @@ ENUM *var = 0;
 ENUM var2 = (ENUM)3;
 enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
 
-void (*PR23733)() = static_cast<void (*)()>((void *)0); // expected-warning {{static_cast between pointer-to-function and pointer-to-object is a Microsoft extension}}
+typedef void (*FnPtrTy)();
+void (*PR23733_1)() = static_cast<FnPtrTy>((void *)0); // expected-warning {{static_cast between pointer-to-function and pointer-to-object is a Microsoft extension}}
+void (*PR23733_2)() = FnPtrTy((void *)0);
+void (*PR23733_3)() = (FnPtrTy)((void *)0);
+void (*PR23733_4)() = reinterpret_cast<FnPtrTy>((void *)0);





More information about the cfe-commits mailing list