diff options
author | Joseph Myers <joseph@codesourcery.com> | 2004-11-20 20:31:52 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2004-11-20 20:31:52 +0000 |
commit | a4ab7973cfe5dfb4b191f795adaaddad831d7657 (patch) | |
tree | 744160b47cb98a4ccacd021c089dc864bfb2cedd /gcc/testsuite/gcc.dg/array-8.c | |
parent | 40806b8b8f7a4d2ba6b926300f6a0dbcf862eb9d (diff) | |
download | gcc-a4ab7973cfe5dfb4b191f795adaaddad831d7657.zip gcc-a4ab7973cfe5dfb4b191f795adaaddad831d7657.tar.gz gcc-a4ab7973cfe5dfb4b191f795adaaddad831d7657.tar.bz2 |
c-typeck.c (build_array_ref): Don't check for index == 0.
* c-typeck.c (build_array_ref): Don't check for index == 0. Make
checks for neither argument being an array or pointer (swapping
the arguments if necessary), the array argument being a pointer to
or array of functions and for -Wchar-subscripts warnings upfront.
testsuite:
* gcc.dg/Wchar-subscripts-1.c, gcc.dg/array-8.c: New tests.
* gcc.dg/pointer-arith-1.c, gcc.dg/pointer-arith-2.c,
gcc.dg/pointer-arith-3.c, gcc.dg/pointer-arith-4.c: Update
expected diagnostics.
From-SVN: r90969
Diffstat (limited to 'gcc/testsuite/gcc.dg/array-8.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/array-8.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/array-8.c b/gcc/testsuite/gcc.dg/array-8.c new file mode 100644 index 0000000..6d0a211 --- /dev/null +++ b/gcc/testsuite/gcc.dg/array-8.c @@ -0,0 +1,49 @@ +/* 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 "error: subscripted value is neither array nor pointer" } */ + p[1.0]; /* { dg-error "error: array subscript is not an integer" } */ + 1.0[a]; /* { dg-error "error: array subscript is not an integer" } */ + fp[0]; /* { dg-error "error: subscripted value is pointer to function" } */ + 0[fp]; /* { dg-error "error: subscripted value is pointer to function" } */ + pv[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */ + 0[pv]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */ + sip[0]; /* { dg-error "error: invalid use of undefined type 'struct si'" } */ + /* { dg-error "error: dereferencing pointer to incomplete type" "" { target *-*-* } 45 } */ + 0[sip]; /* { dg-error "error: invalid use of undefined type 'struct si'" } */ + /* { dg-error "error: dereferencing pointer to incomplete type" "" { target *-*-* } 47 } */ +} |