[clang] [C] Do not diagnose flexible array members with -Wdefault-const-init-field-unsafe (PR #140578)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Mon May 19 18:09:18 PDT 2025


================
@@ -85,3 +85,33 @@ void func() {
   static const int b; // zero-init-var-warning {{default initialization of an object of type 'const int' is incompatible with C++}} \
                          cxx-error {{default initialization of an object of const type 'const int'}}
 }
+
+// Test the behavior of flexible array members. Those cannot be initialized
+// when a stack-allocated object of the structure type is created. We handle
+// degenerate flexible arrays similarly, but only if the array does not
+// actually specify any storage. Note that C++ does not have flexible array
+// members at all, which is why the test is disabled there.
+#ifndef __cplusplus
+struct RealFAM {
----------------
shafik wrote:

I feel bad asking this but should we also check a FAM in a union as well?

https://github.com/llvm/llvm-project/pull/140578


More information about the cfe-commits mailing list