1 |
149 |
jeremybenn |
/* Test diagnostics for arithmetic on void and function pointers.
|
2 |
|
|
Test with -Wpointer-arith. */
|
3 |
|
|
/* Origin: Joseph Myers <joseph@codesourcery.com> */
|
4 |
|
|
/* { dg-do compile } */
|
5 |
|
|
/* { dg-options "-Wpointer-arith" } */
|
6 |
|
|
|
7 |
|
|
void *p;
|
8 |
|
|
void (*f)(void);
|
9 |
|
|
|
10 |
|
|
void
|
11 |
|
|
g (void)
|
12 |
|
|
{
|
13 |
|
|
p + 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
14 |
|
|
p + 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
15 |
|
|
|
16 |
|
|
1 + p; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
17 |
|
|
p - 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
18 |
|
|
p - 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
19 |
|
|
p += 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
20 |
|
|
p += 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
21 |
|
|
p -= 0; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
22 |
|
|
p -= 1; /* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" } */
|
23 |
|
|
f + 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
24 |
|
|
f + 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
25 |
|
|
|
26 |
|
|
1 + f; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
27 |
|
|
f - 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
28 |
|
|
f - 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
29 |
|
|
f += 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
30 |
|
|
f += 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
31 |
|
|
f -= 0; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
32 |
|
|
f -= 1; /* { dg-warning "warning: pointer to a function used in arithmetic" } */
|
33 |
|
|
p[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
|
34 |
|
|
/* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
|
35 |
|
|
0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
|
36 |
|
|
/* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
|
37 |
|
|
f[0]; /* { dg-error "error: subscripted value is pointer to function" } */
|
38 |
|
|
0[f]; /* { dg-error "error: subscripted value is pointer to function" } */
|
39 |
|
|
p - p; /* { dg-warning "warning: pointer of type 'void \\*' used in subtraction" } */
|
40 |
|
|
f - f; /* { dg-warning "warning: pointer to a function used in subtraction" } */
|
41 |
|
|
}
|