diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2015-06-02 22:15:12 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2015-06-02 22:15:12 +0000 |
| commit | 85bd1206796df79a61387d0cc8f75a289850a6c0 (patch) | |
| tree | 5a48e10ed3856fb3e79f34dd1402551820d636af | |
| parent | 9c19d35fa78df605b62fc28e8b960d7999d1e07e (diff) | |
| download | bcm5719-llvm-85bd1206796df79a61387d0cc8f75a289850a6c0.tar.gz bcm5719-llvm-85bd1206796df79a61387d0cc8f75a289850a6c0.zip | |
[MSVC Compatibility] Permit static_cast from void-ptr to function-ptr
The MSVC 2013 and 2015 implementation of std::atomic is specialized for
pointer types. The member functions are implemented using a static_cast
from void-ptr to function-ptr which is not allowed in the standard.
Permit this conversion if -fms-compatibility is present.
This fixes PR23733.
llvm-svn: 238877
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 8 | ||||
| -rw-r--r-- | clang/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 9ccd5adf21a..d79aeb2e8f1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5390,6 +5390,10 @@ def err_bad_const_cast_dest : Error< "which is not a reference, pointer-to-object, or pointer-to-data-member">; def ext_cast_fn_obj : Extension< "cast between pointer-to-function and pointer-to-object is an extension">; +def ext_ms_cast_fn_obj : ExtWarn< + "static_cast between pointer-to-function and pointer-to-object is a " + "Microsoft extension">, + InGroup<Microsoft>; def warn_cxx98_compat_cast_fn_obj : Warning< "cast between pointer-to-function and pointer-to-object is incompatible with C++98">, InGroup<CXX98CompatPedantic>, DefaultIgnore; diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 091e77936c1..8683d03007d 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -1081,6 +1081,14 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, Kind = CK_BitCast; return TC_Success; } + + // Microsoft permits static_cast from 'pointer-to-void' to + // 'pointer-to-function'. + if (Self.getLangOpts().MSVCCompat && DestPointee->isFunctionType()) { + Self.Diag(OpRange.getBegin(), diag::ext_ms_cast_fn_obj) << OpRange; + Kind = CK_BitCast; + return TC_Success; + } } else if (DestType->isObjCObjectPointerType()) { // allow both c-style cast and static_cast of objective-c pointers as diff --git a/clang/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp b/clang/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp index 0c7d354c306..e72878e3024 100644 --- a/clang/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp +++ b/clang/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp @@ -6,3 +6,5 @@ enum ENUM; // expected-warning {{forward references to 'enum' types are a Micros 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}} |

