summaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-20 20:31:52 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-20 20:31:52 +0000
commit20931c08f468f8239334ec3d938e7554a8819998 (patch)
tree744160b47cb98a4ccacd021c089dc864bfb2cedd /gcc/testsuite
parentbb30f677e665bca25e979d13b23a9fc83c83d883 (diff)
downloadgcc-20931c08f468f8239334ec3d938e7554a8819998.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@90969 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/Wchar-subscripts-1.c29
-rw-r--r--gcc/testsuite/gcc.dg/array-8.c49
-rw-r--r--gcc/testsuite/gcc.dg/pointer-arith-1.c4
-rw-r--r--gcc/testsuite/gcc.dg/pointer-arith-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/pointer-arith-3.c4
-rw-r--r--gcc/testsuite/gcc.dg/pointer-arith-4.c4
7 files changed, 93 insertions, 8 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8fe6b3b60ef..ef3ca31020f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2004-11-20 Joseph S. Myers <joseph@codesourcery.com>
+
+ * 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.
+
2004-11-20 Eric Botcazou <ebotcazou@libertysurf.fr>
PR target/18580
diff --git a/gcc/testsuite/gcc.dg/Wchar-subscripts-1.c b/gcc/testsuite/gcc.dg/Wchar-subscripts-1.c
new file mode 100644
index 00000000000..d1efd25026b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wchar-subscripts-1.c
@@ -0,0 +1,29 @@
+/* Test -Wchar-subscripts. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wchar-subscripts" } */
+
+extern int a[];
+int *p;
+char c;
+signed char sc;
+unsigned char uc;
+
+void
+f (void)
+{
+ a[sc];
+ a[uc];
+ sc[a];
+ uc[a];
+ p[sc];
+ p[uc];
+ sc[p];
+ uc[p];
+ a[c]; /* { dg-warning "warning: array subscript has type 'char'" } */
+ p[c]; /* { dg-warning "warning: array subscript has type 'char'" } */
+ /* -Wchar-subscripts does not warn if the char is not syntactically
+ the subscript. */
+ c[a];
+ c[p];
+}
diff --git a/gcc/testsuite/gcc.dg/array-8.c b/gcc/testsuite/gcc.dg/array-8.c
new file mode 100644
index 00000000000..6d0a211461b
--- /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 } */
+}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-1.c b/gcc/testsuite/gcc.dg/pointer-arith-1.c
index fec20547bf3..3bf78873e8f 100644
--- a/gcc/testsuite/gcc.dg/pointer-arith-1.c
+++ b/gcc/testsuite/gcc.dg/pointer-arith-1.c
@@ -32,8 +32,8 @@ g (void)
f -= 1;
p[0]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
- f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
- 0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+ f[0]; /* { dg-error "error: subscripted value is pointer to function" } */
+ 0[f]; /* { dg-error "error: subscripted value is pointer to function" } */
p - p;
f - f;
}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-2.c b/gcc/testsuite/gcc.dg/pointer-arith-2.c
index 8e95ab52078..fde01e102d7 100644
--- a/gcc/testsuite/gcc.dg/pointer-arith-2.c
+++ b/gcc/testsuite/gcc.dg/pointer-arith-2.c
@@ -34,8 +34,8 @@ g (void)
/* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
/* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
- f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
- 0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+ f[0]; /* { dg-error "error: subscripted value is pointer to function" } */
+ 0[f]; /* { dg-error "error: subscripted value is pointer to function" } */
p - p; /* { dg-warning "warning: pointer of type 'void \\*' used in subtraction" } */
f - f; /* { dg-warning "warning: pointer to a function used in subtraction" } */
}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-3.c b/gcc/testsuite/gcc.dg/pointer-arith-3.c
index 90f524101b8..f23f677c8b8 100644
--- a/gcc/testsuite/gcc.dg/pointer-arith-3.c
+++ b/gcc/testsuite/gcc.dg/pointer-arith-3.c
@@ -34,8 +34,8 @@ g (void)
/* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
/* { dg-warning "warning: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
- f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
- 0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+ f[0]; /* { dg-error "error: subscripted value is pointer to function" } */
+ 0[f]; /* { dg-error "error: subscripted value is pointer to function" } */
p - p; /* { dg-warning "warning: pointer of type 'void \\*' used in subtraction" } */
f - f; /* { dg-warning "warning: pointer to a function used in subtraction" } */
}
diff --git a/gcc/testsuite/gcc.dg/pointer-arith-4.c b/gcc/testsuite/gcc.dg/pointer-arith-4.c
index 3e577fc1cb5..b17f9d7a335 100644
--- a/gcc/testsuite/gcc.dg/pointer-arith-4.c
+++ b/gcc/testsuite/gcc.dg/pointer-arith-4.c
@@ -34,8 +34,8 @@ g (void)
/* { dg-error "error: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 33 } */
0[p]; /* { dg-warning "warning: dereferencing 'void \\*' pointer" } */
/* { dg-error "error: pointer of type 'void \\*' used in arithmetic" "array 1" { target *-*-* } 35 } */
- f[0]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
- 0[f]; /* { dg-error "error: subscripted value is neither array nor pointer" } */
+ f[0]; /* { dg-error "error: subscripted value is pointer to function" } */
+ 0[f]; /* { dg-error "error: subscripted value is pointer to function" } */
p - p; /* { dg-error "error: pointer of type 'void \\*' used in subtraction" } */
f - f; /* { dg-error "error: pointer to a function used in subtraction" } */
}