]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6499801> clang does not detect objc type mismatch in conditional...
authorSteve Naroff <snaroff@apple.com>
Thu, 12 Feb 2009 19:05:07 +0000 (19:05 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 12 Feb 2009 19:05:07 +0000 (19:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64393 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjC/conditional-expr-2.m

index 8c3a0a9fa15806ef1cf7f34390b10c10628d8011..628f233d6813c927f64d92618986c5418770fbe0 100644 (file)
@@ -2245,9 +2245,8 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
         // incompatible then make sure to use 'id' as the composite
         // type so the result is acceptable for sending messages to.
 
-        // FIXME: This code should not be localized to here. Also this
-        // should use a compatible check instead of abusing the
-        // canAssignObjCInterfaces code.
+        // FIXME: Consider unifying with 'areComparableObjCPointerTypes'.
+        // It could return the composite type.      
         const ObjCInterfaceType* LHSIface = lhptee->getAsObjCInterfaceType();
         const ObjCInterfaceType* RHSIface = rhptee->getAsObjCInterfaceType();
         if (LHSIface && RHSIface &&
@@ -2258,11 +2257,11 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
           compositeType = rexT;
         } else if (Context.isObjCIdStructType(lhptee) || 
                    Context.isObjCIdStructType(rhptee)) { 
-          // FIXME: This code looks wrong, because isObjCIdStructType checks
-          // the struct but getObjCIdType returns the pointer to
-          // struct. This is horrible and should be fixed.
           compositeType = Context.getObjCIdType();
         } else {
+          Diag(questionLoc, diag::ext_typecheck_comparison_of_distinct_pointers)
+               << lexT << rexT 
+               << lex->getSourceRange() << rex->getSourceRange();
           QualType incompatTy = Context.getObjCIdType();
           ImpCastExprToType(lex, incompatTy);
           ImpCastExprToType(rex, incompatTy);
index d8a2663093742d788a7af6d9e2708ccd9f50d0b0..260482a6da9593dcaa0e94079047e17d41449055 100644 (file)
@@ -8,5 +8,22 @@
 void f0(int cond, A *a, B *b) {
   // Ensure that we can still send a message to result of incompatible
   // conditional expression.
-  [ (cond ? a : b) test ]; // expected-warning {{method '-test' not found}}
+  [ (cond ? a : b) test ]; // expected-warning{{comparison of distinct pointer types ('A *' and 'B *')}} expected-warning {{method '-test' not found}}
+}
+
+@interface NSKey @end
+@interface KeySub : NSKey @end
+
+@interface UpdatesList @end
+
+void foo (int i, NSKey *NSKeyValueCoding_NullValue, UpdatesList *nukedUpdatesList)
+{
+  id obj;
+  NSKey *key;
+  KeySub *keysub;
+
+  obj = i ? NSKeyValueCoding_NullValue : nukedUpdatesList; // expected-warning{{comparison of distinct pointer types ('NSKey *' and 'UpdatesList *')}}
+  key = i ? NSKeyValueCoding_NullValue : nukedUpdatesList; // expected-warning{{comparison of distinct pointer types ('NSKey *' and 'UpdatesList *')}}
+  key = i ? NSKeyValueCoding_NullValue : keysub;
+  keysub = i ? NSKeyValueCoding_NullValue : keysub; // expected-warning{{incompatible pointer types assigning 'NSKey *', expected 'KeySub *'}}
 }