[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 7 03:02:37 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);
----------------
Fznamznon wrote:

Reversed the order.
It seems clang emulates this GCC behavior for 10+ years and changing that can be a disruptive change, I wanted to avoid that.
I added a FIXME highlighting the problem though.

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


More information about the cfe-commits mailing list