1 |
689 |
jeremybenn |
/* Conversions between function and object pointers are not permitted
|
2 |
|
|
in any version of ISO C, even with casts, except for the special
|
3 |
|
|
case of converting a null pointer constant to function pointer
|
4 |
|
|
type. Likewise, comparisons between function and object pointers
|
5 |
|
|
are not permitted. PR c/11234. */
|
6 |
|
|
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
|
7 |
|
|
/* { dg-do compile } */
|
8 |
|
|
/* { dg-options "-pedantic" } */
|
9 |
|
|
|
10 |
|
|
void f(void);
|
11 |
|
|
|
12 |
|
|
void *v1 = f; /* { dg-warning "12:pointer" "bad conversion" } */
|
13 |
|
|
void *v2 = &f; /* { dg-warning "12:pointer" "bad conversion" } */
|
14 |
|
|
void *v3 = (void *)f; /* { dg-warning "12:pointer" "bad conversion" } */
|
15 |
|
|
void *v4 = (void *)&f; /* { dg-warning "12:pointer" "bad conversion" } */
|
16 |
|
|
void *v5;
|
17 |
|
|
char *c1 = f; /* { dg-warning "12:pointer" "bad conversion" } */
|
18 |
|
|
char *c2 = &f; /* { dg-warning "12:pointer" "bad conversion" } */
|
19 |
|
|
char *c3 = (char *)f; /* { dg-warning "12:pointer" "bad conversion" } */
|
20 |
|
|
char *c4 = (char *)&f; /* { dg-warning "12:pointer" "bad conversion" } */
|
21 |
|
|
char *c5;
|
22 |
|
|
void (*fp)(void);
|
23 |
|
|
int a;
|
24 |
|
|
|
25 |
|
|
void
|
26 |
|
|
g(void)
|
27 |
|
|
{
|
28 |
|
|
v5 = f; /* { dg-warning "6:pointer" "bad conversion" } */
|
29 |
|
|
v5 = &f; /* { dg-warning "6:pointer" "bad conversion" } */
|
30 |
|
|
v5 = (void *)f; /* { dg-warning "8:pointer" "bad conversion" } */
|
31 |
|
|
v5 = (void *)&f; /* { dg-warning "8:pointer" "bad conversion" } */
|
32 |
|
|
c5 = f; /* { dg-warning "6:pointer" "bad conversion" } */
|
33 |
|
|
c5 = &f; /* { dg-warning "6:pointer" "bad conversion" } */
|
34 |
|
|
c5 = (char *)f; /* { dg-warning "8:pointer" "bad conversion" } */
|
35 |
|
|
c5 = (char *)&f; /* { dg-warning "8:pointer" "bad conversion" } */
|
36 |
|
|
fp = v5; /* { dg-warning "6:pointer" "bad conversion" } */
|
37 |
|
|
fp = c5; /* { dg-warning "6:pointer" "bad conversion" } */
|
38 |
|
|
fp = (void (*)(void))v5; /* { dg-warning "8:pointer" "bad conversion" } */
|
39 |
|
|
fp = (void (*)(void))c5; /* { dg-warning "8:pointer" "bad conversion" } */
|
40 |
|
|
(a ? f : v3); /* { dg-warning "10:pointer" "bad conversion" } */
|
41 |
|
|
(a ? v2 : fp); /* { dg-warning "11:pointer" "bad conversion" } */
|
42 |
|
|
/* The following are OK. */
|
43 |
|
|
fp = 0;
|
44 |
|
|
fp = (void *)0;
|
45 |
|
|
fp = 0L;
|
46 |
|
|
fp = (void (*)(void))0;
|
47 |
|
|
fp = (void (*)(void))(void *)0;
|
48 |
|
|
(a ? f : 0);
|
49 |
|
|
(a ? f : (void *)0);
|
50 |
|
|
(a ? (void *)0 : fp);
|
51 |
|
|
(a ? 0 : fp);
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
/* The following are OK. */
|
55 |
|
|
void (*fp2)(void) = 0;
|
56 |
|
|
void (*fp3)(void) = (void *)0;
|