]> granicus.if.org Git - clang/commitdiff
Teach Sema::CheckConditionalOperands() to check for ObjCQualifiedIdType's. This fixes...
authorSteve Naroff <snaroff@apple.com>
Sat, 31 May 2008 22:33:45 +0000 (22:33 +0000)
committerSteve Naroff <snaroff@apple.com>
Sat, 31 May 2008 22:33:45 +0000 (22:33 +0000)
<rdar://problem/5967036> clang on xcode: error: incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream *')

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

lib/Sema/SemaExpr.cpp
test/Sema/conditional-expr.m [new file with mode: 0644]

index 500d5b7786eaea7a0df8dfb18dfdf14cd7f2f182..f75c3924a000e8e4cb3a2948a088a0da7a3c0db8 100644 (file)
@@ -972,7 +972,13 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
       return compositeType;
     }
   }
-  
+  // Need to handle "id<xx>" explicitly. Unlike "id", whose canonical type
+  // evaluates to "struct objc_object *" (and is handled above when comparing
+  // id with statically typed objects). FIXME: Do we need an ImpCastExprToType?
+  if (lexT->isObjCQualifiedIdType() || rexT->isObjCQualifiedIdType()) {
+    if (ObjCQualifiedIdTypesAreCompatible(lexT, rexT, true))
+      return Context.getObjCIdType();
+  }
   // Otherwise, the operands are not compatible.
   Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands,
        lexT.getAsString(), rexT.getAsString(),
diff --git a/test/Sema/conditional-expr.m b/test/Sema/conditional-expr.m
new file mode 100644 (file)
index 0000000..d262041
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: clang -fsyntax-only -verify -pedantic %s
+@protocol NSObject
+@end
+
+@protocol DTOutputStreams <NSObject>
+@end
+
+@interface DTFilterOutputStream <DTOutputStreams>
+- nextOutputStream;
+@end
+
+@implementation DTFilterOutputStream
+- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
+  id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
+  self = nextOutputStream;
+  return nextOutputStream ? nextOutputStream : self;
+}
+- nextOutputStream {
+  return self;
+}
+@end