r238877 - [MSVC Compatibility] Permit static_cast from void-ptr to function-ptr
Reid Kleckner
rnk at google.com
Mon Jun 8 16:39:12 PDT 2015
This warns on C-style casts, which it should not:
$ ninja check
[68/414] Building CXX object
lib\ExecutionEngine\RuntimeDyld\CMakeFiles\LLVMRuntimeDyld.dir\RTDyldMemoryManager.cpp.obj
..\lib\ExecutionEngine\RuntimeDyld\RTDyldMemoryManager.cpp(61,6) :
warning: static_cast between pointer-to-function and pointer-to-object is
a Microsoft extension [-Wmicrosoft]
((void (*)(void *))rf)(p);
^~~~~~~~~~~~~~~~~~~~
..\lib\ExecutionEngine\RuntimeDyld\RTDyldMemoryManager.cpp(74,6) :
warning: static_cast between pointer-to-function and pointer-to-object is
a Microsoft extension [-Wmicrosoft]
((void (*)(void *))df)(p);
^~~~~~~~~~~~~~~~~~~~
2 warnings generated.
On Tue, Jun 2, 2015 at 3:15 PM, David Majnemer <david.majnemer at gmail.com>
wrote:
> Author: majnemer
> Date: Tue Jun 2 17:15:12 2015
> New Revision: 238877
>
> URL: http://llvm.org/viewvc/llvm-project?rev=238877&view=rev
> Log:
> [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.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaCast.cpp
> cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=238877&r1=238876&r2=238877&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 2
> 17:15:12 2015
> @@ -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;
>
> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=238877&r1=238876&r2=238877&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Jun 2 17:15:12 2015
> @@ -1081,6 +1081,14 @@ static TryCastResult TryStaticCast(Sema
> 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
>
> Modified: cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp?rev=238877&r1=238876&r2=238877&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp (original)
> +++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp Tue Jun 2
> 17:15:12 2015
> @@ -6,3 +6,5 @@ enum ENUM; // expected-warning {{forward
> 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}}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150608/a3f8bc4f/attachment.html>
More information about the cfe-commits
mailing list