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