blob: e4c949ac7114acf0864e774c31068a6d8d440a02 [file] [log] [blame]
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +00001// RUN: clang -fsyntax-only -verify %s
2
3#include <objc/objc.h>
4
5extern void foo();
6
7@protocol MyProtocol
8- (void) method;
9@end
10
11@interface MyClass
12@end
13
14int main()
15{
16 id obj = nil;
17 id <MyProtocol> obj_p = nil;
18 MyClass *obj_c = nil;
19 Class obj_C = Nil;
20
21 int i = 0;
22 int *j = nil;
23
24 /* These should all generate warnings. */
25
26 obj = i; // expected-warning {{incompatible types assigning 'int' to 'id'}}
27 obj = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'id'}}
28
29 obj_p = i; // expected-error {{incompatible types assigning 'int' to 'id<MyProtocol>' }}
30 obj_p = j; // expected-error {{incompatible types assigning 'int *' to 'id<MyProtocol>'}}
31
32 obj_c = i; // expected-warning {{incompatible types assigning 'int' to 'MyClass *'}}
33 obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'MyClass *'}}
34
35 obj_C = i; // expected-warning {{incompatible types assigning 'int' to 'Class'}}
36 obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'Class'}}
37
38 i = obj; // expected-warning {{incompatible types assigning 'id' to 'int'}}
39 i = obj_p; // expected-error {{incompatible types assigning 'id<MyProtocol>' to 'int'}}
40 i = obj_c; // expected-warning {{incompatible types assigning 'MyClass *' to 'int'}}
41 i = obj_C; // expected-warning {{incompatible types assigning 'Class' to 'int'}}
42
43 j = obj; // expected-warning {{incompatible pointer types assigning 'id' to 'int *'}}
44 j = obj_p; // expected-error {{incompatible types assigning 'id<MyProtocol>' to 'int *'}}
45 j = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *' to 'int *'}}
46 j = obj_C; // expected-warning {{incompatible pointer types assigning 'Class' to 'int *'}}
47
48 if (obj == i) foo() ; // expected-warning {{comparison between pointer and integer ('id' and 'int')}}
49 if (i == obj) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id')}}
50 if (obj == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id' and 'int *')}}
51 if (j == obj) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id')}}
52
53 if (obj_c == i) foo() ; // expected-warning {{comparison between pointer and integer ('MyClass *' and 'int')}}
54 if (i == obj_c) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'MyClass *')}}
55 if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}}
56 if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}}
57
58 if (obj_p == i) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int')}}
59 if (i == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int' and 'id<MyProtocol>')}}
60 if (obj_p == j) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int *')}}
61 if (j == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'id<MyProtocol>')}}
62
63 if (obj_C == i) foo() ; // expected-warning {{comparison between pointer and integer ('Class' and 'int')}}
64 if (i == obj_C) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'Class')}}
65 if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}}
66 if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}}
67
68 return 0;
69}