aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c2x-empty-init-2.c
blob: 0dc81ce5b8ea08f271370ee0685266da98700487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* Test C2X support for empty initializers: invalid use cases.  */
/* { dg-do compile } */
/* { dg-options "-std=c2x -pedantic-errors" } */

/* Empty initialization is invalid for arrays of unknown size.  This is
   diagnosed via the diagnostic for zero-size arrays.  */
int x[] = {}; /* { dg-error "zero or negative size array" } */

void
f (int a)
{
  int x1[] = {}; /* { dg-error "zero or negative size array" } */
  int x2[][a] = {}; /* { dg-error "zero or negative size array" } */
  /* Nonempty VLA initializers are still invalid.  */
  int x3[a] = { 0 }; /* { dg-error "variable-sized object may not be initialized except with an empty initializer" } */
  /* Variable-size compound literals are still invalid.  */
  (void) (int [a]) {}; /* { dg-error "compound literal has variable size" } */
}