1 |
12 |
jlechner |
/* Test various ObjC types assignments and comparisons. */
|
2 |
|
|
/* Author: Nicola Pero . */
|
3 |
|
|
/* { dg-do compile } */
|
4 |
|
|
|
5 |
|
|
#include
|
6 |
|
|
|
7 |
|
|
@protocol MyProtocol
|
8 |
|
|
- (void) foo;
|
9 |
|
|
@end
|
10 |
|
|
|
11 |
|
|
@interface MyClass
|
12 |
|
|
@end
|
13 |
|
|
|
14 |
|
|
@interface MyOtherClass
|
15 |
|
|
- (void) foo;
|
16 |
|
|
@end
|
17 |
|
|
|
18 |
|
|
int main()
|
19 |
|
|
{
|
20 |
|
|
id obj = nil;
|
21 |
|
|
id obj_p = nil;
|
22 |
|
|
MyClass *obj_c = nil;
|
23 |
|
|
MyOtherClass *obj_cp = nil;
|
24 |
|
|
Class obj_C = Nil;
|
25 |
|
|
|
26 |
|
|
/* Assigning to an 'id' variable should never
|
27 |
|
|
generate a warning. */
|
28 |
|
|
obj = obj_p; /* Ok */
|
29 |
|
|
obj = obj_c; /* Ok */
|
30 |
|
|
obj = obj_cp; /* Ok */
|
31 |
|
|
obj = obj_C; /* Ok */
|
32 |
|
|
|
33 |
|
|
/* Assigning to a 'MyClass *' variable should always generate a
|
34 |
|
|
warning, unless done from an 'id'. */
|
35 |
|
|
obj_c = obj; /* Ok */
|
36 |
|
|
obj_c = obj_p; /* { dg-warning "distinct Objective\\-C type" } */
|
37 |
|
|
obj_c = obj_cp; /* { dg-warning "distinct Objective\\-C type" } */
|
38 |
|
|
obj_c = obj_C; /* { dg-warning "distinct Objective\\-C type" } */
|
39 |
|
|
|
40 |
|
|
/* Assigning to an 'id' 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). */
|
44 |
|
|
obj_p = obj; /* Ok */
|
45 |
|
|
obj_p = obj_c; /* { dg-warning "does not implement" } */
|
46 |
|
|
obj_p = obj_cp; /* Ok */
|
47 |
|
|
obj_p = obj_C; /* { dg-warning "distinct Objective\\-C type" } */
|
48 |
|
|
|
49 |
|
|
/* Assigning to a 'MyOtherClass *' variable should always generate
|
50 |
|
|
a warning, unless done from an 'id' or an 'id' (since
|
51 |
|
|
MyOtherClass implements MyProtocol). */
|
52 |
|
|
obj_cp = obj; /* Ok */
|
53 |
|
|
obj_cp = obj_c; /* { dg-warning "distinct Objective\\-C type" } */
|
54 |
|
|
obj_cp = obj_p; /* Ok */
|
55 |
|
|
obj_cp = obj_C; /* { dg-warning "distinct Objective\\-C type" } */
|
56 |
|
|
|
57 |
|
|
/* Any comparison involving an 'id' must be without warnings. */
|
58 |
|
|
if (obj == obj_p) ; /* Ok */ /*Bogus warning here in 2.95.4*/
|
59 |
|
|
if (obj_p == obj) ; /* Ok */
|
60 |
|
|
if (obj == obj_c) ; /* Ok */
|
61 |
|
|
if (obj_c == obj) ; /* Ok */
|
62 |
|
|
if (obj == obj_cp) ; /* Ok */
|
63 |
|
|
if (obj_cp == obj) ; /* Ok */
|
64 |
|
|
if (obj == obj_C) ; /* Ok */
|
65 |
|
|
if (obj_C == obj) ; /* Ok */
|
66 |
|
|
|
67 |
|
|
/* Any comparison between 'MyClass *' and anything which is not an 'id'
|
68 |
|
|
must generate a warning. */
|
69 |
|
|
if (obj_c == obj_p) ; /* { dg-warning "lacks a cast" } */
|
70 |
|
|
if (obj_p == obj_c) ; /* { dg-warning "lacks a cast" } */
|
71 |
|
|
if (obj_c == obj_cp) ; /* { dg-warning "lacks a cast" } */
|
72 |
|
|
if (obj_cp == obj_c) ; /* { dg-warning "lacks a cast" } */
|
73 |
|
|
if (obj_c == obj_C) ; /* { dg-warning "lacks a cast" } */
|
74 |
|
|
if (obj_C == obj_c) ; /* { dg-warning "lacks a cast" } */
|
75 |
|
|
|
76 |
|
|
/* Any comparison between 'MyOtherClass *' (which implements
|
77 |
|
|
MyProtocol) and an 'id' implementing MyProtocol are Ok. */
|
78 |
|
|
if (obj_cp == obj_p) ; /* Ok */
|
79 |
|
|
if (obj_p == obj_cp) ; /* Ok */
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
if (obj_p == obj_C) ; /* { dg-warning "lacks a cast" } */
|
83 |
|
|
if (obj_C == obj_p) ; /* { dg-warning "lacks a cast" } */
|
84 |
|
|
if (obj_cp == obj_C) ; /* { dg-warning "lacks a cast" } */
|
85 |
|
|
if (obj_C == obj_cp) ; /* { dg-warning "lacks a cast" } */
|
86 |
|
|
|
87 |
|
|
return 0;
|
88 |
|
|
}
|