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