Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / C / C2x / n2900_n3011.c
blob4350aa140691b1d5c026b04c78d1b91e31a0f951
1 // RUN: %clang_cc1 -std=c2x -fsyntax-only -Wpre-c2x-compat -verify=compat %s
2 // RUN: %clang_cc1 -std=c17 -fsyntax-only -pedantic -Wno-comment -verify=pedantic %s
4 /* WG14 N2900: yes
5 * Consistent, Warningless, and Intuitive Initialization with {}
6 */
8 /* WG14 N3011: yes
9 * Consistent, Warningless, and Intuitive Initialization with {}
11 void test(void) {
12 struct S { int x, y; } s = {}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
13 pedantic-warning {{use of an empty initializer is a C23 extension}}
14 int i = {}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
15 pedantic-warning {{use of an empty initializer is a C23 extension}}
16 int j = (int){}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
17 pedantic-warning {{use of an empty initializer is a C23 extension}}
19 // C2x 6.7.10p4 says, in part: An array of unknown size shall not be
20 // initialized by an empty initializer.
21 // However, Clang allows zero-sized arrays as an extension in both C and C++,
22 // and this initialization form will deduce the array extent as zero. Given
23 // that we support empty initialization of an unbounded array in C++, we also
24 // support it in C.
25 int unknown_size[] = {}; // pedantic-warning {{zero size arrays are an extension}} \
26 pedantic-warning {{use of an empty initializer is a C23 extension}} \
27 compat-warning {{use of an empty initializer is incompatible with C standards before C23}}
28 int vla[i] = {}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
29 pedantic-warning {{use of an empty initializer is a C23 extension}}
30 int *compound_literal_vla = (int[i]){}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
31 pedantic-warning {{use of an empty initializer is a C23 extension}}
33 struct T {
34 int i;
35 struct S s;
36 } t1 = { 1, {} }; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
37 pedantic-warning {{use of an empty initializer is a C23 extension}}
39 struct T t2 = {
40 1, {
41 2, {} // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
42 pedantic-warning {{use of an empty initializer is a C23 extension}}
46 struct T t3 = {
47 (int){}, // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
48 pedantic-warning {{use of an empty initializer is a C23 extension}}
49 {} // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
50 pedantic-warning {{use of an empty initializer is a C23 extension}}
53 // Ensure that zero initialization does what you'd expect in a constant expr.
54 // FIXME: the "not an ICE" warning is incorrect for C2x, but we don't yet
55 // implement WG14 N3038.
56 _Static_assert((int){} == 0, "what?"); // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
57 pedantic-warning {{use of an empty initializer is a C23 extension}} \
58 pedantic-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}