summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/gnu99-init-1.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2001-01-12 23:18:05 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2001-01-12 23:18:05 +0000
commit989bbcfcda3aeeaf46615f5803648fdfe5d47f56 (patch)
tree61018fce6476697759fec1b7443adbb9e7cc463d /gcc/testsuite/gcc.dg/gnu99-init-1.c
parent8be067eae8acc9a035663489bc25f3bb87bd4f3b (diff)
downloadgcc-989bbcfcda3aeeaf46615f5803648fdfe5d47f56.tar.gz
* c-typeck.c (store_init_value): Don't require constant initializer
elements with -pedantic -std=c99. (digest_init): Change error about non-constant initializer elements into pedwarn. (constructor_range_end): Remove. (constructor_incremental, designator_depth, designator_errorneous): New variables. (struct constructor_stack): Remove range_end, add incremental. (struct constructor_range_stack, constructor_range_stack): New. (struct initializer_stack): Add constructor_range_stack. (finish_init): Set it. (start_init): Likewise. require_constant_elements for non-static trees only if not flag_isoc99. (really_start_incremental_init): Remove constructor_range_end, add constructor_incremental. (pop_init_level): Likewise. (push_init_level): Likewise. If implicit and the subobject had some value set already, preinitialize the level with it. Warn about missing braces only if not pushing due to designators. (set_designator, push_range_stack): New functions. (set_init_label): Use them. (set_init_index): Likewise. Remove constructor_range_end. Error if designator index is outside of array bounds. (add_pending_init): Compare values of purpose index trees, not the trees themselves. Allow overwriting of already initialized element. Issue a warning if it had side-effects. (set_nonincremental_init, set_nonincremental_init_from_string): New functions. (pending_init_member): Rename to... (find_init_member): ...this function. Call set_nonincremental_init if necessary. Compare values of purpose index trees, not the trees themselves. Return the actual value, not just non-zero if something is found. (output_init_element): Remove checks for duplicates. If field has zero size, only check the initializer for correctness. Call set_nonincremental_init if necessary. Push RECORD/ARRAY into AVL if constructor_incremental is zero. Change error about initializers not computable at load time into pedwarn. (output_pending_init_elements): Compare bit positions, not FIELD_DECLs to take into account zero-sized fields. (process_init_element): Use constructor_range_stack to fill all ranges in the designator lists from current level up. * extend.texi: Update documentation for labeled elements. * gcc.c-torture/execute/20000801-3.x: Remove. * gcc.dg/c90-init-1.c: New test. * gcc.dg/c99-init-1.c: New test. * gcc.dg/c99-init-2.c: New test. * gcc.dg/gnu99-init-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38968 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/gnu99-init-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/gnu99-init-1.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/gnu99-init-1.c b/gcc/testsuite/gcc.dg/gnu99-init-1.c
new file mode 100644
index 00000000000..c78f17647c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu99-init-1.c
@@ -0,0 +1,62 @@
+/* Test for GNU extensions to C99 designated initializers */
+/* Origin: Jakub Jelinek <jakub@redhat.com> */
+/* { dg-do run } */
+/* { dg-options "-std=gnu99" } */
+
+typedef __SIZE_TYPE__ size_t;
+extern int memcmp (const void *, const void *, size_t);
+extern void abort (void);
+extern void exit (int);
+
+int a[][2][4] = { [2 ... 4][0 ... 1][2 ... 3] = 1, [2] = 2, [2][0][2] = 3 };
+struct E {};
+struct F { struct E H; };
+struct G { int I; struct E J; int K; };
+struct H { int I; struct F J; int K; };
+struct G k = { .J = {}, 1 };
+struct H l = { .J.H = {}, 2 };
+struct H m = { .J = {}, 3 };
+struct I { int J; int K[3]; int L; };
+struct M { int N; struct I O[3]; int P; };
+struct M n[] = { [0 ... 5].O[1 ... 2].K[0 ... 1] = 4, 5, 6, 7 };
+
+int main (void)
+{
+ int x, y, z;
+
+ if (a[2][0][0] != 2 || a[2][0][2] != 3)
+ abort ();
+ a[2][0][0] = 0;
+ a[2][0][2] = 1;
+ for (x = 0; x <= 4; x++)
+ for (y = 0; y <= 1; y++)
+ for (z = 0; z <= 3; z++)
+ if (a[x][y][z] != (x >= 2 && z >= 2))
+ abort ();
+ if (k.I || l.I || m.I || k.K != 1 || l.K != 2 || m.K != 3)
+ abort ();
+ for (x = 0; x <= 5; x++)
+ {
+ if (n[x].N || n[x].O[0].J || n[x].O[0].L)
+ abort ();
+ for (y = 0; y <= 2; y++)
+ if (n[x].O[0].K[y])
+ abort ();
+ for (y = 1; y <= 2; y++)
+ {
+ if (n[x].O[y].J)
+ abort ();
+ if (n[x].O[y].K[0] != 4)
+ abort ();
+ if (n[x].O[y].K[1] != 4)
+ abort ();
+ if ((x < 5 || y < 2) && (n[x].O[y].K[2] || n[x].O[y].L))
+ abort ();
+ }
+ if (x < 5 && n[x].P)
+ abort ();
+ }
+ if (n[5].O[2].K[2] != 5 || n[5].O[2].L != 6 || n[5].P != 7)
+ abort ();
+ exit (0);
+}