blob: 881fd2b5553b8ae147797f714eaf9a22202165ff [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify -pedantic %s
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +00002
Fariborz Jahanian38860122008-01-09 00:33:05 +00003#define nil (void *)0;
4#define Nil (void *)0;
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +00005
6extern void foo();
7
8@protocol MyProtocol
9- (void) method;
10@end
11
12@interface MyClass
13@end
14
15int main()
16{
17 id obj = nil;
18 id <MyProtocol> obj_p = nil;
19 MyClass *obj_c = nil;
20 Class obj_C = Nil;
21
22 int i = 0;
23 int *j = nil;
24
25 /* These should all generate warnings. */
26
Chris Lattnerb7b61152008-01-04 18:22:42 +000027 obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000028 obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000029
Steve Naroff20373222008-06-03 14:04:54 +000030 obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id<MyProtocol>'}}
Steve Naroff4084c302009-07-23 01:01:38 +000031 obj_p = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id<MyProtocol>'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000032
Chris Lattnerb7b61152008-01-04 18:22:42 +000033 obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000034 obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'MyClass *'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000035
Chris Lattnerb7b61152008-01-04 18:22:42 +000036 obj_C = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'Class'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000037 obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000038
Chris Lattnerb7b61152008-01-04 18:22:42 +000039 i = obj; // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
Steve Naroff20373222008-06-03 14:04:54 +000040 i = obj_p; // expected-warning {{incompatible pointer to integer conversion assigning 'id<MyProtocol>', expected 'int'}}
Chris Lattnerb7b61152008-01-04 18:22:42 +000041 i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning 'MyClass *', expected 'int'}}
42 i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning 'Class', expected 'int'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000043
Chris Lattner5cf216b2008-01-04 18:04:52 +000044 j = obj; // expected-warning {{incompatible pointer types assigning 'id', expected 'int *'}}
Steve Naroff4084c302009-07-23 01:01:38 +000045 j = obj_p; // expected-warning {{incompatible pointer types assigning 'id<MyProtocol>', expected 'int *'}}
Chris Lattner5cf216b2008-01-04 18:04:52 +000046 j = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *', expected 'int *'}}
47 j = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'int *'}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000048
49 if (obj == i) foo() ; // expected-warning {{comparison between pointer and integer ('id' and 'int')}}
50 if (i == obj) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id')}}
51 if (obj == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id' and 'int *')}}
52 if (j == obj) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id')}}
53
54 if (obj_c == i) foo() ; // expected-warning {{comparison between pointer and integer ('MyClass *' and 'int')}}
55 if (i == obj_c) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'MyClass *')}}
56 if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}}
57 if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}}
58
Steve Naroff20373222008-06-03 14:04:54 +000059 if (obj_p == i) foo() ; // expected-warning {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}}
60 if (i == obj_p) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id<MyProtocol>')}}
Steve Naroff87f3b932008-10-20 18:19:10 +000061 if (obj_p == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'int *')}}
62 if (j == obj_p) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id<MyProtocol>')}}
Fariborz Jahaniandc5c01b2007-12-22 00:17:49 +000063
64 if (obj_C == i) foo() ; // expected-warning {{comparison between pointer and integer ('Class' and 'int')}}
65 if (i == obj_C) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'Class')}}
66 if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}}
67 if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}}
68
69 return 0;
70}