1 /* Test various ObjC types assignments and comparisons. */
2 /* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
3 /* { dg-do compile } */
13 @interface MyOtherClass <MyProtocol>
20 id<MyProtocol> obj_p = nil;
22 MyOtherClass *obj_cp = nil;
25 /* Assigning to an 'id' variable should never
26 generate a warning. */
29 obj = obj_cp; /* Ok */
32 /* Assigning to a 'MyClass *' variable should always generate a
33 warning, unless done from an 'id'. */
35 obj_c = obj_p; /* { dg-warning "distinct Objective\\-C type" } */
36 obj_c = obj_cp; /* { dg-warning "distinct Objective\\-C type" } */
37 obj_c = obj_C; /* { dg-warning "distinct Objective\\-C type" } */
39 /* Assigning to an 'id<MyProtocol>' variable should generate a
40 warning if done from a 'MyClass *' (which doesn't implement
41 MyProtocol), but not from an 'id' or from a 'MyOtherClass *'
42 (which implements MyProtocol). */
44 obj_p = obj_c; /* { dg-warning "does not implement" } */
45 obj_p = obj_cp; /* Ok */
46 obj_p = obj_C; /* { dg-warning "distinct Objective\\-C type" } */
48 /* Assigning to a 'MyOtherClass *' variable should always generate
49 a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
50 MyOtherClass implements MyProtocol). */
51 obj_cp = obj; /* Ok */
52 obj_cp = obj_c; /* { dg-warning "distinct Objective\\-C type" } */
53 obj_cp = obj_p; /* Ok */
54 obj_cp = obj_C; /* { dg-warning "distinct Objective\\-C type" } */
56 /* Any comparison involving an 'id' must be without warnings. */
57 if (obj == obj_p) ; /* Ok */ /*Bogus warning here in 2.95.4*/
58 if (obj_p == obj) ; /* Ok */
59 if (obj == obj_c) ; /* Ok */
60 if (obj_c == obj) ; /* Ok */
61 if (obj == obj_cp) ; /* Ok */
62 if (obj_cp == obj) ; /* Ok */
63 if (obj == obj_C) ; /* Ok */
64 if (obj_C == obj) ; /* Ok */
66 /* Any comparison between 'MyClass *' and anything which is not an 'id'
67 must generate a warning. */
68 if (obj_c == obj_p) ; /* { dg-warning "lacks a cast" } */
69 if (obj_p == obj_c) ; /* { dg-warning "lacks a cast" } */
70 if (obj_c == obj_cp) ; /* { dg-warning "lacks a cast" } */
71 if (obj_cp == obj_c) ; /* { dg-warning "lacks a cast" } */
72 if (obj_c == obj_C) ; /* { dg-warning "lacks a cast" } */
73 if (obj_C == obj_c) ; /* { dg-warning "lacks a cast" } */
75 /* Any comparison between 'MyOtherClass *' (which implements
76 MyProtocol) and an 'id' implementing MyProtocol are Ok. */
77 if (obj_cp == obj_p) ; /* Ok */
78 if (obj_p == obj_cp) ; /* Ok */
81 if (obj_p == obj_C) ; /* { dg-warning "lacks a cast" } */
82 if (obj_C == obj_p) ; /* { dg-warning "lacks a cast" } */
83 if (obj_cp == obj_C) ; /* { dg-warning "lacks a cast" } */
84 if (obj_C == obj_cp) ; /* { dg-warning "lacks a cast" } */