Another test case, testing a variety of objective-c type comparisons.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45302 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Sema/objc-comptypes-7.m b/test/Sema/objc-comptypes-7.m
new file mode 100644
index 0000000..e4c949a
--- /dev/null
+++ b/test/Sema/objc-comptypes-7.m
@@ -0,0 +1,69 @@
+// RUN: clang -fsyntax-only -verify %s
+
+#include <objc/objc.h>
+
+extern void foo();
+
+@protocol MyProtocol
+- (void) method;
+@end
+
+@interface MyClass
+@end
+
+int main()
+{
+ id obj = nil;
+ id <MyProtocol> obj_p = nil;
+ MyClass *obj_c = nil;
+ Class obj_C = Nil;
+
+ int i = 0;
+ int *j = nil;
+
+ /* These should all generate warnings. */
+
+ obj = i; // expected-warning {{incompatible types assigning 'int' to 'id'}}
+ obj = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'id'}}
+
+ obj_p = i; // expected-error {{incompatible types assigning 'int' to 'id<MyProtocol>' }}
+ obj_p = j; // expected-error {{incompatible types assigning 'int *' to 'id<MyProtocol>'}}
+
+ obj_c = i; // expected-warning {{incompatible types assigning 'int' to 'MyClass *'}}
+ obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'MyClass *'}}
+
+ obj_C = i; // expected-warning {{incompatible types assigning 'int' to 'Class'}}
+ obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'Class'}}
+
+ i = obj; // expected-warning {{incompatible types assigning 'id' to 'int'}}
+ i = obj_p; // expected-error {{incompatible types assigning 'id<MyProtocol>' to 'int'}}
+ i = obj_c; // expected-warning {{incompatible types assigning 'MyClass *' to 'int'}}
+ i = obj_C; // expected-warning {{incompatible types assigning 'Class' to 'int'}}
+
+ j = obj; // expected-warning {{incompatible pointer types assigning 'id' to 'int *'}}
+ j = obj_p; // expected-error {{incompatible types assigning 'id<MyProtocol>' to 'int *'}}
+ j = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *' to 'int *'}}
+ j = obj_C; // expected-warning {{incompatible pointer types assigning 'Class' to 'int *'}}
+
+ if (obj == i) foo() ; // expected-warning {{comparison between pointer and integer ('id' and 'int')}}
+ if (i == obj) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id')}}
+ if (obj == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id' and 'int *')}}
+ if (j == obj) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id')}}
+
+ if (obj_c == i) foo() ; // expected-warning {{comparison between pointer and integer ('MyClass *' and 'int')}}
+ if (i == obj_c) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'MyClass *')}}
+ 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 == 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>')}}
+
+ if (obj_C == i) foo() ; // expected-warning {{comparison between pointer and integer ('Class' and 'int')}}
+ if (i == obj_C) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'Class')}}
+ if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}}
+ if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}}
+
+ return 0;
+}