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
5 * Consistent, Warningless, and Intuitive Initialization with {}
9 * Consistent, Warningless, and Intuitive Initialization with {}
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
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
}}
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
}}
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
}}
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
}}