Skip to content

Commit

Permalink
Add some additional comments to this test; NFC
Browse files Browse the repository at this point in the history
It isn't immediately obvious why that code should be accepted given the
wording of C2x 6.7.10p4, so this adds a comment explaining that there
is an existing extension to support zero-sized arrays in C, and that
empty initialization of an unbounded array in C++ deduces the array
extent as zero, so C is exposing the same extension as in C++.
  • Loading branch information
AaronBallman committed Apr 5, 2023
1 parent 77d667b commit 78d0d59
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/test/C/C2x/n2900_n3011.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ void test(void) {
pedantic-warning {{use of an empty initializer is a C2x extension}}
int j = (int){}; // compat-warning {{use of an empty initializer is incompatible with C standards before C2x}} \
pedantic-warning {{use of an empty initializer is a C2x extension}}

// C2x 6.7.10p4 says, in part: An array of unknown size shall not be
// initialized by an empty initializer.
// However, Clang allows zero-sized arrays as an extension in both C and C++,
// and this initialization form will deduce the array extent as zero. Given
// that we support empty initialization of an unbounded array in C++, we also
// support it in C.
int unknown_size[] = {}; // pedantic-warning {{zero size arrays are an extension}} \
pedantic-warning {{use of an empty initializer is a C2x extension}} \
compat-warning {{use of an empty initializer is incompatible with C standards before C2x}}
Expand Down

0 comments on commit 78d0d59

Please sign in to comment.