summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/init-bad-2.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-29 11:35:34 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-29 11:35:34 +0000
commit3ef7f5472e9aa7dd8de53ad14bb503957f15b62f (patch)
tree90e4515759bd82802db7b8d774b90f54139c454a /gcc/testsuite/gcc.dg/init-bad-2.c
parent312f7161718ebe1867f96b8ae3eca2c73a398d15 (diff)
downloadgcc-3ef7f5472e9aa7dd8de53ad14bb503957f15b62f.tar.gz
* gcc.dg/Wnested-externs-1.c, gcc.dg/decl-7.c, gcc.dg/decl-8.c,
gcc.dg/if-empty-1.c, gcc.dg/init-bad-1.c, gcc.dg/init-bad-2.c, gcc.dg/init-bad-3.c, gcc.dg/parm-mismatch-1.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91465 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/init-bad-2.c')
-rw-r--r--gcc/testsuite/gcc.dg/init-bad-2.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/init-bad-2.c b/gcc/testsuite/gcc.dg/init-bad-2.c
new file mode 100644
index 00000000000..794cc412db3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/init-bad-2.c
@@ -0,0 +1,33 @@
+/* Test diagnostics for various bad initializers. Test cases with
+ standard syntax with -pedantic. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic" } */
+
+void f(void);
+void g(void) = f; /* { dg-error "error: function 'g' is initialized like a variable" } */
+
+void h(a)
+ int a = 1; /* { dg-error "error: parameter 'a' is initialized" } */
+{
+ struct s x = { 0 }; /* { dg-error "error: variable 'x' has initializer but incomplete type" } */
+ /* { dg-warning "excess elements|near init" "" { target *-*-* } 13 } */
+ /* { dg-error "storage size" "" { target *-*-* } 13 } */
+}
+
+char s[1] = "x";
+char s1[1] = { "x" };
+char t[1] = "xy"; /* { dg-warning "warning: initializer-string for array of chars is too long" } */
+char t1[1] = { "xy" }; /* { dg-warning "warning: initializer-string for array of chars is too long" } */
+char u[1] = { "x", "x" }; /* { dg-error "error: excess elements in char array initializer" } */
+/* { dg-error "near init" "" { target *-*-* } 22 } */
+
+int j = { 1 };
+
+int k = { 1, 2 }; /* { dg-warning "warning: excess elements in scalar initializer" } */
+/* { dg-warning "near init" "" { target *-*-* } 27 } */
+
+int a1[1] = { [1] = 0 }; /* { dg-error "error: array index in initializer exceeds array bounds" } */
+/* { dg-error "near init" "" { target *-*-* } 30 } */
+int a2[1] = { [-1] = 0 }; /* { dg-error "error: array index in initializer exceeds array bounds" } */
+/* { dg-error "near init" "" { target *-*-* } 32 } */