[clang-tools-extra] [clangd] Add inlay hints for forwarding direct init (PR #176635)

Tobias Ribizel via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 20 01:46:57 PST 2026


================
@@ -773,11 +773,26 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
     bool HasNonDefaultArgs = false;
 
     ArrayRef<const ParmVarDecl *> Params, ForwardedParams;
+
     // Resolve parameter packs to their forwarded parameter
     SmallVector<const ParmVarDecl *> ForwardedParamsStorage;
+    // If args are direct-initialized
+    const CXXRecordDecl *CxxRecord{};
+
     if (Callee.Decl) {
       Params = maybeDropCxxExplicitObjectParameters(Callee.Decl->parameters());
-      ForwardedParamsStorage = resolveForwardingParameters(Callee.Decl);
+
+      [&]() {
+        auto Params = resolveForwardingParameters(Callee.Decl);
+        if (std::holds_alternative<decltype(ForwardedParamsStorage)>(Params)) {
+          ForwardedParamsStorage =
+              std::get<decltype(ForwardedParamsStorage)>(Params);
+        }
+        if (std::holds_alternative<decltype(CxxRecord)>(Params)) {
+          CxxRecord = std::get<decltype(CxxRecord)>(Params);
+        }
+      }();
----------------
upsj wrote:

Does this actually need to be an IIFE, or can we just use different variable names? I'm guessing the goal is to shadow the Params variable? Name is just a suggestion.
```suggestion
      auto ParamsOrRecord = resolveForwardingParameters(Callee.Decl);
      if (std::holds_alternative<decltype(ForwardedParamsStorage)>(ParamsOrRecord)) {
        ForwardedParamsStorage =
            std::get<decltype(ForwardedParamsStorage)>(ParamsOrRecord);
      }
      if (std::holds_alternative<decltype(CxxRecord)>(ParamsOrRecord)) {
        CxxRecord = std::get<decltype(CxxRecord)>(ParamsOrRecord);
      }
```

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


More information about the cfe-commits mailing list