[clang] [clang] Add FixItHint for designated init order (PR #173136)

Mythreya Kuricheti via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 20 17:37:48 PST 2025


================
@@ -3092,6 +3094,65 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
         PrevField = *FI;
       }
 
+      const auto GenerateDesignatedInitReorderingFixit =
+          [&](SemaBase::SemaDiagnosticBuilder &Diags) {
+            struct ReorderInfo {
+              int Pos{};
+              const Expr *InitExpr{};
+            };
+
+            llvm::SmallDenseMap<IdentifierInfo *, int> MemberNameInx{};
+            llvm::SmallVector<ReorderInfo, 16> ReorderedInitExprs{};
+
+            const auto *CxxRecord =
+                IList->getSemanticForm()->getType()->getAsCXXRecordDecl();
+
+            for (const auto &Field : CxxRecord->fields()) {
+              MemberNameInx[Field->getIdentifier()] = Field->getFieldIndex();
+            }
+
+            for (const auto *Init : IList->inits()) {
----------------
MythreyaK wrote:

> ditto on the type

sorry, did you mean the `const auto *CxxRecord` [at this line](https://github.com/llvm/llvm-project/pull/173136/changes#diff-4b27f959f0d9ede7ea1992939cdded750c3a0ae6a2b3669f833282c35035d4eaR3107)?

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


More information about the cfe-commits mailing list