summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/gnu99-init-1.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/gnu99-init-1.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/gnu99-init-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/gnu99-init-1.c80
1 files changed, 80 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 000000000..009c8515f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu99-init-1.c
@@ -0,0 +1,80 @@
+/* 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 };
+struct M o[] = { [0 ... 5].O = { [1 ... 2].K[0 ... 1] = 4 },
+ [5].O[2].K[2] = 5, 6, 7 };
+struct M p[] = { [0 ... 5].O[1 ... 2].K = { [0 ... 1] = 4 },
+ [5].O[2].K[2] = 5, 6, 7 };
+int q[3][3] = { [0 ... 1] = { [1 ... 2] = 23 }, [1][2] = 24 };
+int r[1] = { [0 ... 1 - 1] = 27 };
+
+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 ();
+ if (memcmp (n, o, sizeof (n)) || sizeof (n) != sizeof (o))
+ abort ();
+ if (memcmp (n, p, sizeof (n)) || sizeof (n) != sizeof (p))
+ abort ();
+ if (q[0][0] || q[0][1] != 23 || q[0][2] != 23)
+ abort ();
+ if (q[1][0] || q[1][1] != 23 || q[1][2] != 24)
+ abort ();
+ if (q[2][0] || q[2][1] || q[2][2])
+ abort ();
+ if (r[0] != 27)
+ abort ();
+ exit (0);
+}