File: array-8.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (48 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (4)
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
42
43
44
45
46
47
48
/* Test diagnostics for array references.  */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-std=gnu89" } */

struct s { char c[1]; };
struct s f (void);
_Bool b;
char c;
enum e { E } e;
extern int a[];
int *p;
void *pv;
void (*fp)(void);
struct si *sip;

void
g (void)
{
  a[b];
  a[c];
  a[e];
  p[b];
  p[c];
  p[e];
  b[a];
  c[a];
  e[a];
  b[p];
  c[p];
  e[p];
  /* These two should be treated the same.  In particular, a "neither
     array nor pointer" bogus warning used to be given for the
     second.  */
  f().c[0];
  0[f().c];
  /* Various invalid cases.  */
  c[c]; /* { dg-error "subscripted value is neither array nor pointer nor vector" } */
  p[1.0]; /* { dg-error "array subscript is not an integer" } */
  1.0[a]; /* { dg-error "array subscript is not an integer" } */
  fp[0]; /* { dg-error "subscripted value is pointer to function" } */
  0[fp]; /* { dg-error "subscripted value is pointer to function" } */
  pv[0]; /* { dg-warning "dereferencing 'void \\*' pointer" } */
  0[pv]; /* { dg-warning "dereferencing 'void \\*' pointer" } */
  sip[0]; /* { dg-error "invalid use of undefined type 'struct si'" } */
  /* { dg-error "dereferencing pointer to incomplete type" "incomplete" { target *-*-* } .-1 } */
  0[sip]; /* { dg-error "invalid use of undefined type 'struct si'" } */
}