forked from OSchip/llvm-project
In Microsoft mode, allow conversion from pointer to integral type no matter what size the integral type is. Necessary to parse MFC code.
Example: void f(char *ptr) { char var = (char)ptr; } llvm-svn: 131201
This commit is contained in:
parent
2a9dbbbb12
commit
b796b632a8
|
@ -1514,9 +1514,11 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
|
|||
if (DestType->isIntegralType(Self.Context)) {
|
||||
assert(srcIsPtr && "One type must be a pointer");
|
||||
// C++ 5.2.10p4: A pointer can be explicitly converted to any integral
|
||||
// type large enough to hold it.
|
||||
if (Self.Context.getTypeSize(SrcType) >
|
||||
Self.Context.getTypeSize(DestType)) {
|
||||
// type large enough to hold it; except in Microsoft mode, where the
|
||||
// integral type size doesn't matter.
|
||||
if ((Self.Context.getTypeSize(SrcType) >
|
||||
Self.Context.getTypeSize(DestType)) &&
|
||||
!Self.getLangOptions().Microsoft) {
|
||||
msg = diag::err_bad_reinterpret_cast_small_int;
|
||||
return TC_Failed;
|
||||
}
|
||||
|
|
|
@ -189,3 +189,11 @@ void function_to_voidptr_conv() {
|
|||
void *a2 = &function_prototype;
|
||||
void *a3 = function_ptr;
|
||||
}
|
||||
|
||||
|
||||
void pointer_to_integral_type_conv(char* ptr) {
|
||||
char ch = (char)ptr;
|
||||
short sh = (short)ptr;
|
||||
ch = (char)ptr;
|
||||
sh = (short)ptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue