[clang-tools-extra] [clangd] Add designator hints for parenthesis aggregate initialization (PR #170642)

Mythreya Kuricheti via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 7 02:48:14 PST 2025


================
@@ -699,6 +699,26 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
     return InstantiatedFunction->getParamDecl(ParamIdx);
   }
 
+  bool VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
+    // TODO: Lang check needed?
+    if (!Cfg.InlayHints.Designators &&
+        AST.getLangOpts().LangStd >= LangStandard::Kind::lang_cxx20)
+      return true;
+
+    if (const auto *CXXRecord = E->getType()->getAsCXXRecordDecl()) {
+      const auto &InitExprs = E->getInitExprs();
+      auto RecordFields = CXXRecord->fields().begin();
+
+      for (size_t I = 0; I < InitExprs.size();
+           ++I, RecordFields = std::next(RecordFields)) {
----------------
MythreyaK wrote:

That's pretty cool, thanks! Would you prefer it if I add you as the co-author for this change as crediting you, because I'm using your suggestion almost verbatim? 

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


More information about the cfe-commits mailing list