diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/c2x-empty-init-2.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/c2x-empty-init-2.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/c2x-empty-init-2.c b/gcc/testsuite/gcc.dg/c2x-empty-init-2.c new file mode 100644 index 0000000..0dc81ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-empty-init-2.c @@ -0,0 +1,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" } */ +} |