Add some additional comments to this test; NFC
authorAaron Ballman <aaron@aaronballman.com>
Wed, 5 Apr 2023 17:13:42 +0000 (13:13 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Wed, 5 Apr 2023 17:15:34 +0000 (13:15 -0400)
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++.

clang/test/C/C2x/n2900_n3011.c

index b0de79e..6aaff33 100644 (file)
@@ -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}}