Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 2 | |
Fariborz Jahanian | 3886012 | 2008-01-09 00:33:05 +0000 | [diff] [blame] | 3 | #define nil (void *)0; |
| 4 | #define Nil (void *)0; |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 5 | |
| 6 | extern void foo(); |
| 7 | |
| 8 | @protocol MyProtocol |
| 9 | - (void) method; |
| 10 | @end |
| 11 | |
| 12 | @interface MyClass |
| 13 | @end |
| 14 | |
| 15 | int 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 Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 27 | obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}} |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 28 | obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}} |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 29 | |
Steve Naroff | 2037322 | 2008-06-03 14:04:54 +0000 | [diff] [blame] | 30 | obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id<MyProtocol>'}} |
Steve Naroff | 4084c30 | 2009-07-23 01:01:38 +0000 | [diff] [blame] | 31 | obj_p = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id<MyProtocol>'}} |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 32 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 33 | obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}} |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 34 | obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'MyClass *'}} |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 35 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 36 | obj_C = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'Class'}} |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 37 | obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}} |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 38 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 39 | i = obj; // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}} |
Steve Naroff | 2037322 | 2008-06-03 14:04:54 +0000 | [diff] [blame] | 40 | i = obj_p; // expected-warning {{incompatible pointer to integer conversion assigning 'id<MyProtocol>', expected 'int'}} |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 41 | 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 Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 44 | j = obj; // expected-warning {{incompatible pointer types assigning 'id', expected 'int *'}} |
Steve Naroff | 4084c30 | 2009-07-23 01:01:38 +0000 | [diff] [blame] | 45 | j = obj_p; // expected-warning {{incompatible pointer types assigning 'id<MyProtocol>', expected 'int *'}} |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 46 | 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 Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 48 | |
| 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 Naroff | 2037322 | 2008-06-03 14:04:54 +0000 | [diff] [blame] | 59 | 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 Naroff | 87f3b93 | 2008-10-20 18:19:10 +0000 | [diff] [blame] | 61 | 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 Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 63 | |
| 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 | |
Fariborz Jahanian | 528adb1 | 2010-03-24 21:00:27 +0000 | [diff] [blame^] | 69 | Class bar1 = Nil; |
| 70 | Class <MyProtocol> bar = Nil; |
| 71 | bar = bar1; |
| 72 | bar1 = bar; |
| 73 | |
Fariborz Jahanian | dc5c01b | 2007-12-22 00:17:49 +0000 | [diff] [blame] | 74 | return 0; |
| 75 | } |