]> granicus.if.org Git - clang/commitdiff
Allow implicit pointer/int conversions on ObjCQualifiedIdTypes in Sema::CheckCompareO...
authorSteve Naroff <snaroff@apple.com>
Tue, 3 Jun 2008 14:04:54 +0000 (14:04 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 3 Jun 2008 14:04:54 +0000 (14:04 +0000)
Fixes <rdar://problem/5980804> clang on xcode: error: incompatible type sending 'id<XDUMLType>', expected 'NSCellType'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51902 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/objc-comptypes-7.m

index c384a9a5a2c92b4f7c00eb8d071ac9918f5a3425..8b31d8856a78c1c69e47d14fd187f734565ab0e2 100644 (file)
@@ -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)) {
-    ImpCastExprToType(rex, lType); 
-    return Context.IntTy;
+  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(),
index 6e5ff0282fdd71273cb441d79f9017a04116a3c6..ef3a7790a3d3b952ec20512212e52108ed5c6678 100644 (file)
@@ -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>')}}