[llvm] [clang] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 6 10:21:00 PST 2023
================
@@ -802,9 +845,25 @@ 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 missing fields warning are bound to how
+ // many elements the initializer list originally was provided, perform
+ // them before the list is expanded.
+ bool WarnIfMissingField =
+ !SForm->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) &&
+ ILE->getNumInits();
+
+ // Disable check for missing fields when designators are used in C to
+ // match gcc behaviour.
+ // FIXME: Should we emulate possible gcc warning bug?
+ WarnIfMissingField &=
+ !(!SemaRef.getLangOpts().CPlusPlus && hasAnyDesignatedInits(SForm));
----------------
AaronBallman wrote:
```suggestion
SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);
```
Applying de Morgan's law helps make this a bit more clear, I think.
https://github.com/llvm/llvm-project/pull/70829
More information about the cfe-commits
mailing list