aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2014-07-30 15:02:59 +0000
committerTom Tromey <tromey@gcc.gnu.org>2014-07-30 15:02:59 +0000
commit976d5a222fc23279e239ad926472c7810869e494 (patch)
tree45b34e40286f6fd87f049a30ca4443da457a0501 /gcc/testsuite
parent41c79d60e56ed6c48f2b52ff9e9b750420cf9cbf (diff)
downloadgcc-976d5a222fc23279e239ad926472c7810869e494.zip
gcc-976d5a222fc23279e239ad926472c7810869e494.tar.gz
gcc-976d5a222fc23279e239ad926472c7810869e494.tar.bz2
re PR c/59855 (Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers)
2014-07-30 Tom Tromey <tromey@redhat.com> PR c/59855 * doc/invoke.texi (Warning Options): Document -Wdesignated-init. * doc/extend.texi (Type Attributes): Document designated_init attribute. 2014-07-30 Tom Tromey <tromey@redhat.com> PR c/59855 * c.opt (Wdesignated-init): New option. * c-common.c (c_common_attribute_table): Add "designated_init". (handle_designated_init): New function. 2014-07-30 Tom Tromey <tromey@redhat.com> * c-typeck.c (struct constructor_stack) <designator_depth>: New field. (really_start_incremental_init, push_init_level): Initialize designator_depth. (pop_init_level): Set global designator_depth. (process_init_element): Check for designated_init attribute. From-SVN: r213293
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/Wdesignated-init.c107
2 files changed, 112 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 93511d5..a334ad7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-07-30 Tom Tromey <tromey@redhat.com>
+
+ PR c/59855
+ * gcc.dg/Wdesignated-init.c: New file.
+
2014-07-29 Jan Hubicka <hubicka@ucw.cz>
* g++.dg/ipa/devirt-34.C: New testcase.
diff --git a/gcc/testsuite/gcc.dg/Wdesignated-init.c b/gcc/testsuite/gcc.dg/Wdesignated-init.c
new file mode 100644
index 0000000..b9ca572
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wdesignated-init.c
@@ -0,0 +1,107 @@
+/* PR c/59855 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+typedef int vvv __attribute__((designated_init)); /* { dg-error "only valid" } */
+
+union U {
+ int a;
+ double b;
+} __attribute__((designated_init)); /* { dg-error "only valid" } */
+
+enum E { ONE, TWO } __attribute__((designated_init)); /* { dg-error "only valid" } */
+
+struct Pok {
+ int x;
+ int y;
+};
+
+struct Des {
+ int x;
+ int y;
+} __attribute__ ((designated_init));
+
+struct Des d1 = { 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
+struct Des d2 = { .x = 5, .y = 5 };
+struct Des d3 = { .x = 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
+
+struct Des fd1 (void)
+{
+ return (struct Des) { 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Des fd2 (void)
+{
+ return (struct Des) { .x = 5, .y = 5 };
+}
+
+struct Des fd3 (void)
+{
+ return (struct Des) { .x = 5, 5 }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Wrap {
+ struct Pok p;
+ struct Des d;
+} __attribute__ ((designated_init));
+
+struct Wrap w1 = { { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+struct Wrap w2 = { .p = { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+struct Wrap w3 = { .p = { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+struct Wrap w4 = { { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+struct Wrap w5 = { .p = { 0, 1 }, .d = { .x = 2, .y = 3} };
+
+struct Wrap w6 = { { 0, 1 }, .d.x = 2, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
+struct Wrap w7 = { .p = { 0, 1 }, .d.x = 2, .d.y = 3 };
+struct Wrap w8 = { .p = { 0, 1 }, .d = { 2, 0 }, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
+struct Wrap w9 = { .p = { 0, 1 }, .d = { .x = 2 }, .d.y = 3 };
+
+struct Wrap fw1 (void)
+{
+ return (struct Wrap) { { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+};
+
+struct Wrap fw2 (void)
+{
+ return (struct Wrap) { .p = { 0, 1 }, { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Wrap fw3 (void)
+{
+ return (struct Wrap) { .p = { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Wrap fw4 (void)
+{
+ return (struct Wrap) { { 0, 1 }, .d = { 2, 3} }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Wrap fw5 (void)
+{
+ return (struct Wrap) { .p = { 0, 1 }, .d = { .x = 2, .y = 3} };
+}
+
+struct Wrap fw6 (void)
+{
+ return (struct Wrap) { { 0, 1 }, .d.x = 2, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Wrap fw7 (void)
+{
+ return (struct Wrap) { .p = { 0, 1 }, .d.x = 2, .d.y = 3 };
+}
+
+struct Wrap fw8 (void)
+{
+ return (struct Wrap) { .p = { 0, 1 }, .d = { 2, 0 }, .d.y = 3 }; /* { dg-warning "(positional|near initialization)" } */
+}
+
+struct Wrap fw9 (void)
+{
+ return (struct Wrap) { .p = { 0, 1 }, .d = { .x = 2 }, .d.y = 3 };
+}
+
+struct Des da[] = {
+ { .x = 1, .y = 2 },
+ { 5, 5 } /* { dg-warning "(positional|near initialization)" } */
+};