blob: 3e6a9d343465ff9a58b44a30975d814162e1fdd0 [file] [log] [blame]
Chris Lattner5cf216b2008-01-04 18:04:52 +00001// RUN: clang -fsyntax-only -verify -pedantic %s
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +00002
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
Chris Lattnerb7b61152008-01-04 18:22:42 +000026 obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000027 obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000028
Chris Lattner5cf216b2008-01-04 18:04:52 +000029 obj_p = i; // expected-error {{incompatible type assigning 'int', expected 'id<MyProtocol>' }}
30 obj_p = j; // expected-error {{incompatible type assigning 'int *', expected 'id<MyProtocol>'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000031
Chris Lattnerb7b61152008-01-04 18:22:42 +000032 obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000033 obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'MyClass *'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000034
Chris Lattnerb7b61152008-01-04 18:22:42 +000035 obj_C = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'Class'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000036 obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000037
Chris Lattnerb7b61152008-01-04 18:22:42 +000038 i = obj; // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000039 i = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int'}}
Chris Lattnerb7b61152008-01-04 18:22:42 +000040 i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning 'MyClass *', expected 'int'}}
41 i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning 'Class', expected 'int'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000042
Chris Lattner5cf216b2008-01-04 18:04:52 +000043 j = obj; // expected-warning {{incompatible pointer types assigning 'id', expected 'int *'}}
44 j = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int *'}}
45 j = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *', expected 'int *'}}
46 j = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'int *'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000047
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}