summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Woverride-init-1.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-30 19:46:06 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-30 19:46:06 +0000
commitf1f157ae356ebcb4948ab910aad5711ca70c6aaa (patch)
treee7f9e9ef9055bb20c3907865efd402c942dc4871 /gcc/testsuite/gcc.dg/Woverride-init-1.c
parent16ed7fb2c8a7fd227f037804800768994453f6b5 (diff)
downloadgcc-f1f157ae356ebcb4948ab910aad5711ca70c6aaa.tar.gz
PR c/24010
* c.opt (Woverride-init): New. * c-opts.c (c_common_post_options): Default warn_override_init to extra_warnings. * c-typeck.c (add_pending_init, output_init_element): Warn for overriding initializers without side effects. * doc/invoke.texi (-Woverride-init): Document. (-Wextra): Update. testsuite: * gcc.dg/Woverride-init-1.c, gcc.dg/Woverride-init-2.c, gcc.dg/Woverride-init-3.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117334 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/Woverride-init-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/Woverride-init-1.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Woverride-init-1.c b/gcc/testsuite/gcc.dg/Woverride-init-1.c
new file mode 100644
index 00000000000..29eca3095cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverride-init-1.c
@@ -0,0 +1,28 @@
+/* Test for warnings for overriding designated initializers:
+ -Woverride-init. Bug 24010. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Woverride-init" } */
+
+struct s { int a; int b; int c; };
+union u { char a; long long b; };
+
+struct s s0 = {
+ .a = 1,
+ .b = 2,
+ .a = 3, /* { dg-warning "initialized field overwritten|near init" } */
+ 4, /* { dg-warning "initialized field overwritten|near init" } */
+ 5
+};
+
+union u u0 = {
+ .a = 1,
+ .b = 2, /* { dg-warning "initialized field overwritten|near init" } */
+ .a = 3 }; /* { dg-warning "initialized field overwritten|near init" } */
+
+int a[5] = {
+ [0] = 1,
+ [1] = 2,
+ [0] = 3, /* { dg-warning "initialized field overwritten|near init" } */
+ [2] = 4
+};