c: Support C2x empty initializer braces
[platform/upstream/gcc.git] / gcc / testsuite / gcc.dg / c2x-empty-init-2.c
1 /* Test C2X support for empty initializers: invalid use cases.  */
2 /* { dg-do compile } */
3 /* { dg-options "-std=c2x -pedantic-errors" } */
4
5 /* Empty initialization is invalid for arrays of unknown size.  This is
6    diagnosed via the diagnostic for zero-size arrays.  */
7 int x[] = {}; /* { dg-error "zero or negative size array" } */
8
9 void
10 f (int a)
11 {
12   int x1[] = {}; /* { dg-error "zero or negative size array" } */
13   int x2[][a] = {}; /* { dg-error "zero or negative size array" } */
14   /* Nonempty VLA initializers are still invalid.  */
15   int x3[a] = { 0 }; /* { dg-error "variable-sized object may not be initialized except with an empty initializer" } */
16   /* Variable-size compound literals are still invalid.  */
17   (void) (int [a]) {}; /* { dg-error "compound literal has variable size" } */
18 }