Allow implicit pointer/int conversions on ObjCQualifiedIdTypes in Sema::CheckCompareOperands() and Sema::CheckAssignmentConstraints().
Fixes <rdar://problem/5980804> clang on xcode: error: incompatible type sending 'id<XDUMLType>', expected 'NSCellType'. llvm-svn: 51902
This commit is contained in:
parent
0b225dac9b
commit
b788d9bd27
|
@ -1301,6 +1301,11 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
|
|||
if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType()) {
|
||||
if (ObjCQualifiedIdTypesAreCompatible(lhsType, rhsType, false))
|
||||
return Compatible;
|
||||
// Relax integer conversions like we do for pointers below.
|
||||
if (rhsType->isIntegerType())
|
||||
return IntToPointer;
|
||||
if (lhsType->isIntegerType())
|
||||
return PointerToInt;
|
||||
return Incompatible;
|
||||
}
|
||||
|
||||
|
@ -1647,12 +1652,14 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation loc,
|
|||
ImpCastExprToType(rex, lType); // promote the pointer to pointer
|
||||
return Context.IntTy;
|
||||
}
|
||||
if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())
|
||||
&& ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) {
|
||||
if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())) {
|
||||
if (ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) {
|
||||
ImpCastExprToType(rex, lType);
|
||||
return Context.IntTy;
|
||||
}
|
||||
if (lType->isPointerType() && rType->isIntegerType()) {
|
||||
}
|
||||
if ((lType->isPointerType() || lType->isObjCQualifiedIdType()) &&
|
||||
rType->isIntegerType()) {
|
||||
if (!RHSIsNull)
|
||||
Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
|
||||
lType.getAsString(), rType.getAsString(),
|
||||
|
@ -1660,7 +1667,8 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation loc,
|
|||
ImpCastExprToType(rex, lType); // promote the integer to pointer
|
||||
return Context.IntTy;
|
||||
}
|
||||
if (lType->isIntegerType() && rType->isPointerType()) {
|
||||
if (lType->isIntegerType() &&
|
||||
(rType->isPointerType() || rType->isObjCQualifiedIdType())) {
|
||||
if (!LHSIsNull)
|
||||
Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
|
||||
lType.getAsString(), rType.getAsString(),
|
||||
|
|
|
@ -27,7 +27,7 @@ int main()
|
|||
obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}}
|
||||
obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}}
|
||||
|
||||
obj_p = i; // expected-error {{incompatible type assigning 'int', expected 'id<MyProtocol>' }}
|
||||
obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id<MyProtocol>'}}
|
||||
obj_p = j; // expected-error {{incompatible type assigning 'int *', expected 'id<MyProtocol>'}}
|
||||
|
||||
obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}}
|
||||
|
@ -37,7 +37,7 @@ int main()
|
|||
obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}}
|
||||
|
||||
i = obj; // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
|
||||
i = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int'}}
|
||||
i = obj_p; // expected-warning {{incompatible pointer to integer conversion assigning 'id<MyProtocol>', expected 'int'}}
|
||||
i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning 'MyClass *', expected 'int'}}
|
||||
i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning 'Class', expected 'int'}}
|
||||
|
||||
|
@ -56,8 +56,8 @@ int main()
|
|||
if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}}
|
||||
if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}}
|
||||
|
||||
if (obj_p == i) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int')}}
|
||||
if (i == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int' and 'id<MyProtocol>')}}
|
||||
if (obj_p == i) foo() ; // expected-warning {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}}
|
||||
if (i == obj_p) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id<MyProtocol>')}}
|
||||
if (obj_p == j) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int *')}}
|
||||
if (j == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'id<MyProtocol>')}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue