[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)
Richard Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 13:55:24 PST 2023
================
@@ -802,9 +842,19 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
}
}
} else {
+ InitListExpr *SForm =
+ ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm();
// The fields beyond ILE->getNumInits() are default initialized, so in
// order to leave them uninitialized, the ILE is expanded and the extra
// fields are then filled with NoInitExpr.
+
+ // Some checks that required for MFI warning are bound to how many
+ // elements the initializer list originally was provided, perform them
+ // before the list is expanded
+ bool MaybeEmitMFIWarning =
+ !SForm->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) &&
+ ILE->getNumInits() &&
+ !(hasAnyDesignatedInits(SForm) && !SemaRef.getLangOpts().CPlusPlus);
----------------
zygoloid wrote:
Reverse the order of these checks to avoid scanning the whole initializer list here in C++ mode. Please also add a comment here to say we're doing this for GCC compatibility. (Though I question whether we should be! This seems like emulating a GCC warning bug, which we usually don't do.)
https://github.com/llvm/llvm-project/pull/70829
More information about the llvm-commits
mailing list