[clang] 78d0d59 - Add some additional comments to this test; NFC

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 5 10:15:43 PDT 2023


Author: Aaron Ballman
Date: 2023-04-05T13:15:34-04:00
New Revision: 78d0d59209bf858435bcd19046e94fce0386ace8

URL: https://github.com/llvm/llvm-project/commit/78d0d59209bf858435bcd19046e94fce0386ace8
DIFF: https://github.com/llvm/llvm-project/commit/78d0d59209bf858435bcd19046e94fce0386ace8.diff

LOG: Add some additional comments to this test; NFC

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++.

Added: 
    

Modified: 
    clang/test/C/C2x/n2900_n3011.c

Removed: 
    


################################################################################
diff  --git a/clang/test/C/C2x/n2900_n3011.c b/clang/test/C/C2x/n2900_n3011.c
index b0de79e9a516f..6aaff3374c168 100644
--- a/clang/test/C/C2x/n2900_n3011.c
+++ b/clang/test/C/C2x/n2900_n3011.c
@@ -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}}


        


More information about the cfe-commits mailing list