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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 12 06:44:15 PST 2024


================
@@ -2363,23 +2356,32 @@ void InitListChecker::CheckStructUnionTypes(
   }
 
   // Emit warnings for missing struct field initializers.
-  if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
-      !RD->isUnion()) {
-    // It is possible we have one or more unnamed bitfields remaining.
-    // Find first (if any) named field and emit warning.
-    for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-                                                           : Field,
-                                    end = RD->field_end();
-         it != end; ++it) {
-      if (HasDesignatedInit && InitializedFields.count(*it))
-        continue;
+  if (!VerifyOnly && InitializedSomething && !RD->isUnion()) {
+    // Disable missing fields check for:
+    // - Zero initializers
+    // - Designated initializers (only in C). This matches gcc behaviour.
+    bool DisableCheck =
+        IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) ||
+        (HasDesignatedInit && !SemaRef.getLangOpts().CPlusPlus);
----------------
AaronBallman wrote:

This can be hoisted into the preceding `if` statement so we drop a level of indentation below.

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


More information about the cfe-commits mailing list