1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
15 @interface MyOtherClass <MyProtocol>
22 id<MyProtocol> obj_p = nil;
24 MyOtherClass *obj_cp = nil;
27 /* Assigning to an 'id' variable should never
28 generate a warning. */
31 obj = obj_cp; /* Ok */
34 /* Assigning to a 'MyClass *' variable should always generate a
35 warning, unless done from an 'id'. */
37 obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'MyOtherClass *'}}
38 obj_c = obj_C; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'Class'}}
40 /* Assigning to an 'id<MyProtocol>' variable should generate a
41 warning if done from a 'MyClass *' (which doesn't implement
42 MyProtocol), but not from an 'id' or from a 'MyOtherClass *'
43 (which implements MyProtocol). */
45 obj_p = obj_c; // expected-warning {{ assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}}
46 obj_p = obj_cp; /* Ok */
47 obj_p = obj_C; // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'Class'}}
49 /* Assigning to a 'MyOtherClass *' variable should always generate
50 a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
51 MyOtherClass implements MyProtocol). */
52 obj_cp = obj; /* Ok */
53 obj_cp = obj_c; // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'MyClass *'}}
54 obj_cp = obj_p; /* Ok */
55 obj_cp = obj_C; // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'Class'}}
57 /* Any comparison involving an 'id' must be without warnings. */
58 if (obj == obj_p) foo() ; /* Ok */ /*Bogus warning here in 2.95.4*/
59 if (obj_p == obj) foo() ; /* Ok */
60 if (obj == obj_c) foo() ; /* Ok */
61 if (obj_c == obj) foo() ; /* Ok */
62 if (obj == obj_cp) foo() ; /* Ok */
63 if (obj_cp == obj) foo() ; /* Ok */
64 if (obj == obj_C) foo() ; /* Ok */
65 if (obj_C == obj) foo() ; /* Ok */
67 /* Any comparison between 'MyClass *' and anything which is not an 'id'
68 must generate a warning. */
69 if (obj_p == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'MyClass *')}}
71 if (obj_c == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}}
72 if (obj_cp == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
74 if (obj_c == obj_C) foo() ;
75 if (obj_C == obj_c) foo() ;
77 /* Any comparison between 'MyOtherClass *' (which implements
78 MyProtocol) and an 'id' implementing MyProtocol are Ok. */
79 if (obj_cp == obj_p) foo() ; /* Ok */
80 if (obj_p == obj_cp) foo() ; /* Ok */
83 if (obj_p == obj_C) foo() ;
84 if (obj_C == obj_p) foo() ;
85 if (obj_cp == obj_C) foo() ;
86 if (obj_C == obj_cp) foo() ;