1// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s 2 3#define nil (void *)0; 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 integer to pointer conversion assigning to 'id' from 'int'}} 27 obj = j; // expected-warning {{incompatible pointer types assigning to 'id' from 'int *'}} 28 29 obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning to 'id<MyProtocol>' from 'int'}} 30 obj_p = j; // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'int *'}} 31 32 obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning to 'MyClass *' from 'int'}} 33 obj_c = j; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'int *'}} 34 35 obj_C = i; // expected-warning {{incompatible integer to pointer conversion assigning to 'Class' from 'int'}} 36 obj_C = j; // expected-warning {{incompatible pointer types assigning to 'Class' from 'int *'}} 37 38 i = obj; // expected-warning {{incompatible pointer to integer conversion assigning to 'int' from 'id'}} 39 i = obj_p; // expected-warning {{incompatible pointer to integer conversion assigning to 'int' from 'id<MyProtocol>'}} 40 i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning to 'int' from 'MyClass *'}} 41 i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning to 'int' from 'Class'}} 42 43 j = obj; // expected-warning {{incompatible pointer types assigning to 'int *' from 'id'}} 44 j = obj_p; // expected-warning {{incompatible pointer types assigning to 'int *' from 'id<MyProtocol>'}} 45 j = obj_c; // expected-warning {{incompatible pointer types assigning to 'int *' from 'MyClass *'}} 46 j = obj_C; // expected-warning {{incompatible pointer types assigning to 'int *' from 'Class'}} 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-warning {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}} 59 if (i == obj_p) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id<MyProtocol>')}} 60 if (obj_p == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'int *')}} 61 if (j == obj_p) foo() ; // expected-warning {{comparison of distinct pointer types ('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 Class bar1 = nil; 69 Class <MyProtocol> bar = nil; 70 bar = bar1; 71 bar1 = bar; 72 73 return 0; 74} 75