[clang] [clang] Add -Wmissing-designated-field-initializers (PR #81364)

Vadim D. via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 4 14:35:33 PST 2024


================
@@ -2363,8 +2356,11 @@ void InitListChecker::CheckStructUnionTypes(
   }
 
   // Emit warnings for missing struct field initializers.
-  if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
-      !RD->isUnion()) {
+  // This check is disabled for designated initializers in C.
+  // This matches gcc behaviour.
+  if (!VerifyOnly && InitializedSomething && !RD->isUnion() &&
+      !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) &&
+      !(HasDesignatedInit && !SemaRef.getLangOpts().CPlusPlus)) {
----------------
vvd170501 wrote:

> I am asking for the list of '!'s to be shorter/grouped into a couple of 'bools' with descriptive names

Like this? Other checks seem unrelated to each other.
```diff
+ bool IsCDesignatedInitializer = HasDesignatedInit && !SemaRef.getLangOpts().CPlusPlus;
  if (!VerifyOnly && InitializedSomething && !RD->isUnion() &&
      !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) &&
-     !(HasDesignatedInit && !SemaRef.getLangOpts().CPlusPlus)) {
+     !IsCDesignatedInitializer) {
```

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


More information about the cfe-commits mailing list