r251738 - [MSVC Compat] Permit conversions from pointer-to-function to pointer-to-object iff -fms-compatibility
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 31 17:50:13 PDT 2015
I think we more commonly say "function pointer":
$ grep 'pointer-to-function' include/clang/Basic/Diagnostic*td | wc -l
3
$ grep 'function pointer' include/clang/Basic/Diagnostic*td | wc -l
7
For "object pointer" and "pointer-to-object" it's currently a tie. For
"member pointer" and "pointer-to-member", the former is more common too. We
should probably make all of these consistent – any preferences? "foo
pointer" reads easier to me than "pointer-to-foo", but I'm not a native
speaker.
On Sat, Oct 31, 2015 at 1:42 AM, David Majnemer via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: majnemer
> Date: Sat Oct 31 03:42:14 2015
> New Revision: 251738
>
> URL: http://llvm.org/viewvc/llvm-project?rev=251738&view=rev
> Log:
> [MSVC Compat] Permit conversions from pointer-to-function to
> pointer-to-object iff -fms-compatibility
>
> We permit implicit conversion from pointer-to-function to
> pointer-to-object when -fms-extensions is specified. This is rather
> unfortunate, move this into -fms-compatibility and only permit it within
> system headers unless -Wno-error=microsoft-cast is specified.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaOverload.cpp
> cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp
> cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=251738&r1=251737&r2=251738&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Oct 31
> 03:42:14 2015
> @@ -2635,6 +2635,10 @@ def warn_impcast_null_pointer_to_integer
> def warn_impcast_floating_point_to_bool : Warning<
> "implicit conversion turns floating-point number into bool: %0 to
> %1">,
> InGroup<ImplicitConversionFloatingPointToBool>;
> +def ext_ms_impcast_fn_obj : ExtWarn<
> + "implicit conversion between pointer-to-function and pointer-to-object
> is a "
> + "Microsoft extension">,
> + InGroup<MicrosoftCast>, DefaultError, SFINAEFailure;
>
> def warn_impcast_pointer_to_bool : Warning<
> "address of%select{| function| array}0 '%1' will always evaluate to "
>
> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=251738&r1=251737&r2=251738&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Oct 31 03:42:14 2015
> @@ -2104,7 +2104,7 @@ bool Sema::IsPointerConversion(Expr *Fro
> }
>
> // MSVC allows implicit function to void* type conversion.
> - if (getLangOpts().MicrosoftExt && FromPointeeType->isFunctionType() &&
> + if (getLangOpts().MSVCCompat && FromPointeeType->isFunctionType() &&
> ToPointeeType->isVoidType()) {
> ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
> ToPointeeType,
> @@ -2666,6 +2666,14 @@ bool Sema::CheckPointerConversion(Expr *
> // The conversion was successful.
> Kind = CK_DerivedToBase;
> }
> +
> + if (!IsCStyleOrFunctionalCast && FromPointeeType->isFunctionType()
> &&
> + ToPointeeType->isVoidType()) {
> + assert(getLangOpts().MSVCCompat &&
> + "this should only be possible with MSVCCompat!");
> + Diag(From->getExprLoc(), diag::ext_ms_impcast_fn_obj)
> + << From->getSourceRange();
> + }
> }
> } else if (const ObjCObjectPointerType *ToPtrType =
> ToType->getAs<ObjCObjectPointerType>()) {
>
> Modified: cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp?rev=251738&r1=251737&r2=251738&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp (original)
> +++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp Sat Oct 31
> 03:42:14 2015
> @@ -12,3 +12,12 @@ void (*PR23733_1)() = static_cast<FnPtrT
> void (*PR23733_2)() = FnPtrTy((void *)0);
> void (*PR23733_3)() = (FnPtrTy)((void *)0);
> void (*PR23733_4)() = reinterpret_cast<FnPtrTy>((void *)0);
> +
> +long function_prototype(int a);
> +long (*function_ptr)(int a);
> +
> +void function_to_voidptr_conv() {
> + void *a1 = function_prototype; // expected-warning {{implicit
> conversion between pointer-to-function and pointer-to-object is a Microsoft
> extension}}
> + void *a2 = &function_prototype; // expected-warning {{implicit
> conversion between pointer-to-function and pointer-to-object is a Microsoft
> extension}}
> + void *a3 = function_ptr; // expected-warning {{implicit
> conversion between pointer-to-function and pointer-to-object is a Microsoft
> extension}}
> +}
>
> Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=251738&r1=251737&r2=251738&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
> +++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Sat Oct 31 03:42:14 2015
> @@ -153,16 +153,6 @@ static void static_func() // expected-wa
> extern const int static_var; // expected-note {{previous declaration is
> here}}
> static const int static_var = 3; // expected-warning {{redeclaring
> non-static 'static_var' as static is a Microsoft extension}}
>
> -long function_prototype(int a);
> -long (*function_ptr)(int a);
> -
> -void function_to_voidptr_conv() {
> - void *a1 = function_prototype;
> - void *a2 = &function_prototype;
> - void *a3 = function_ptr;
> -}
> -
> -
> void pointer_to_integral_type_conv(char* ptr) {
> char ch = (char)ptr;
> short sh = (short)ptr;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151031/b5fc0f4a/attachment.html>
More information about the cfe-commits
mailing list