(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
array-8.c
       1  /* Test diagnostics for array references.  */
       2  /* Origin: Joseph Myers <joseph@codesourcery.com> */
       3  /* { dg-do compile } */
       4  /* { dg-options "-std=gnu89" } */
       5  
       6  struct s { char c[1]; };
       7  struct s f (void);
       8  _Bool b;
       9  char c;
      10  enum e { E } e;
      11  extern int a[];
      12  int *p;
      13  void *pv;
      14  void (*fp)(void);
      15  struct si *sip;
      16  
      17  void
      18  g (void)
      19  {
      20    a[b];
      21    a[c];
      22    a[e];
      23    p[b];
      24    p[c];
      25    p[e];
      26    b[a];
      27    c[a];
      28    e[a];
      29    b[p];
      30    c[p];
      31    e[p];
      32    /* These two should be treated the same.  In particular, a "neither
      33       array nor pointer" bogus warning used to be given for the
      34       second.  */
      35    f().c[0];
      36    0[f().c];
      37    /* Various invalid cases.  */
      38    c[c]; /* { dg-error "subscripted value is neither array nor pointer nor vector" } */
      39    p[1.0]; /* { dg-error "array subscript is not an integer" } */
      40    1.0[a]; /* { dg-error "array subscript is not an integer" } */
      41    fp[0]; /* { dg-error "subscripted value is pointer to function" } */
      42    0[fp]; /* { dg-error "subscripted value is pointer to function" } */
      43    pv[0]; /* { dg-warning "dereferencing 'void \\*' pointer" } */
      44    0[pv]; /* { dg-warning "dereferencing 'void \\*' pointer" } */
      45    sip[0]; /* { dg-error "invalid use of undefined type 'struct si'" } */
      46    0[sip]; /* { dg-error "invalid use of undefined type 'struct si'" } */
      47  }