1 |
149 |
jeremybenn |
/* Test warnings for assignments and comparisons between ObjC and C types. */
|
2 |
|
|
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
3 |
|
|
/* { dg-do compile } */
|
4 |
|
|
#include <objc/objc.h>
|
5 |
|
|
|
6 |
|
|
/* The NeXT runtime headers do not define NULL. */
|
7 |
|
|
#ifndef NULL
|
8 |
|
|
#define NULL ((void *)0)
|
9 |
|
|
#endif
|
10 |
|
|
|
11 |
|
|
@protocol MyProtocol
|
12 |
|
|
- (void) method;
|
13 |
|
|
@end
|
14 |
|
|
|
15 |
|
|
@interface MyClass
|
16 |
|
|
@end
|
17 |
|
|
|
18 |
|
|
int main()
|
19 |
|
|
{
|
20 |
|
|
id obj = nil;
|
21 |
|
|
id <MyProtocol> obj_p = nil;
|
22 |
|
|
MyClass *obj_c = nil;
|
23 |
|
|
Class obj_C = Nil;
|
24 |
|
|
|
25 |
|
|
int i = 0;
|
26 |
|
|
int *j = NULL;
|
27 |
|
|
|
28 |
|
|
/* These should all generate warnings. */
|
29 |
|
|
|
30 |
|
|
obj = i; /* { dg-warning "pointer from integer without a cast" } */
|
31 |
|
|
obj = j; /* { dg-warning "incompatible pointer type" } */
|
32 |
|
|
|
33 |
|
|
obj_p = i; /* { dg-warning "pointer from integer without a cast" } */
|
34 |
|
|
obj_p = j; /* { dg-warning "incompatible pointer type" } */
|
35 |
|
|
|
36 |
|
|
obj_c = i; /* { dg-warning "pointer from integer without a cast" } */
|
37 |
|
|
obj_c = j; /* { dg-warning "incompatible pointer type" } */
|
38 |
|
|
|
39 |
|
|
obj_C = i; /* { dg-warning "pointer from integer without a cast" } */
|
40 |
|
|
obj_C = j; /* { dg-warning "incompatible pointer type" } */
|
41 |
|
|
|
42 |
|
|
i = obj; /* { dg-warning "integer from pointer without a cast" } */
|
43 |
|
|
i = obj_p; /* { dg-warning "integer from pointer without a cast" } */
|
44 |
|
|
i = obj_c; /* { dg-warning "integer from pointer without a cast" } */
|
45 |
|
|
i = obj_C; /* { dg-warning "integer from pointer without a cast" } */
|
46 |
|
|
|
47 |
|
|
j = obj; /* { dg-warning "incompatible pointer type" } */
|
48 |
|
|
j = obj_p; /* { dg-warning "incompatible pointer type" } */
|
49 |
|
|
j = obj_c; /* { dg-warning "incompatible pointer type" } */
|
50 |
|
|
j = obj_C; /* { dg-warning "incompatible pointer type" } */
|
51 |
|
|
|
52 |
|
|
if (obj == i) ; /* { dg-warning "comparison between pointer and integer" } */
|
53 |
|
|
if (i == obj) ; /* { dg-warning "comparison between pointer and integer" } */
|
54 |
|
|
if (obj == j) ; /* { dg-warning "lacks a cast" } */
|
55 |
|
|
if (j == obj) ; /* { dg-warning "lacks a cast" } */
|
56 |
|
|
|
57 |
|
|
if (obj_c == i) ; /*{ dg-warning "comparison between pointer and integer" }*/
|
58 |
|
|
if (i == obj_c) ; /*{ dg-warning "comparison between pointer and integer" }*/
|
59 |
|
|
if (obj_c == j) ; /* { dg-warning "lacks a cast" } */
|
60 |
|
|
if (j == obj_c) ; /* { dg-warning "lacks a cast" } */
|
61 |
|
|
|
62 |
|
|
if (obj_p == i) ; /*{ dg-warning "comparison between pointer and integer" }*/
|
63 |
|
|
if (i == obj_p) ; /*{ dg-warning "comparison between pointer and integer" }*/
|
64 |
|
|
if (obj_p == j) ; /* { dg-warning "lacks a cast" } */
|
65 |
|
|
if (j == obj_p) ; /* { dg-warning "lacks a cast" } */
|
66 |
|
|
|
67 |
|
|
if (obj_C == i) ; /*{ dg-warning "comparison between pointer and integer" }*/
|
68 |
|
|
if (i == obj_C) ; /*{ dg-warning "comparison between pointer and integer" }*/
|
69 |
|
|
if (obj_C == j) ; /* { dg-warning "lacks a cast" } */
|
70 |
|
|
if (j == obj_C) ; /* { dg-warning "lacks a cast" } */
|
71 |
|
|
|
72 |
|
|
return 0;
|
73 |
|
|
}
|