[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. llvm-svn: 251738
This commit is contained in:
parent
3817486c47
commit
6bf02820bc
|
@ -2635,6 +2635,10 @@ def warn_impcast_null_pointer_to_integer : Warning<
|
|||
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 "
|
||||
|
|
|
@ -2104,7 +2104,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
|
|||
}
|
||||
|
||||
// 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 *From, QualType ToType,
|
|||
// 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>()) {
|
||||
|
|
|
@ -12,3 +12,12 @@ void (*PR23733_1)() = static_cast<FnPtrTy>((void *)0); // expected-warning {{sta
|
|||
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}}
|
||||
}
|
||||
|
|
|
@ -153,16 +153,6 @@ static void static_func() // expected-warning {{redeclaring non-static 'static_f
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue