[clang] [C] Do not diagnose flexible array members with -Wdefault-const-init-field-unsafe (PR #140578)
Bill Wendling via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 12:57:16 PDT 2025
================
@@ -6513,6 +6513,14 @@ static bool canPerformArrayCopy(const InitializedEntity &Entity) {
static const FieldDecl *getConstField(const RecordDecl *RD) {
assert(!isa<CXXRecordDecl>(RD) && "Only expect to call this in C mode");
for (const FieldDecl *FD : RD->fields()) {
+ // If the field is a flexible array member, we don't want to consider it
+ // as a const field because there's no way to initialize the FAM anyway.
+ if (Decl::isFlexibleArrayMemberLike(
+ FD->getASTContext(), FD, FD->getType(),
+ LangOptions::StrictFlexArraysLevelKind::ZeroOrIncomplete,
----------------
bwendling wrote:
Would it be better to use `getLangOpts().getStrictFlexArraysLevel()` instead of hard-coding `ZeroOrIncomplete`? If `-fstrict-flex-arrays=<n>` is set, then we may not expect there to be storage available in the flex array.
https://github.com/llvm/llvm-project/pull/140578
More information about the cfe-commits
mailing list