[clang] [clang-tools-extra] clangd: Extend reference search with constructor calls through forwarding (PR #169742)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 23 20:41:02 PST 2025
================
@@ -1040,5 +1038,86 @@ bool isExpandedFromParameterPack(const ParmVarDecl *D) {
return getUnderlyingPackType(D) != nullptr;
}
+bool isLikelyForwardingFunction(const FunctionTemplateDecl *FT) {
+ const auto *FD = FT->getTemplatedDecl();
+ const auto NumParams = FD->getNumParams();
+ // Check whether its last parameter is a parameter pack...
+ if (NumParams > 0) {
+ const auto *LastParam = FD->getParamDecl(NumParams - 1);
+ if (const auto *PET = dyn_cast<PackExpansionType>(LastParam->getType())) {
+ // ... of the type T&&... or T...
+ const auto BaseType = PET->getPattern().getNonReferenceType();
+ if (const auto *TTPT =
+ dyn_cast<TemplateTypeParmType>(BaseType.getTypePtr())) {
+ // ... whose template parameter comes from the function directly
+ if (FT->getTemplateParameters()->getDepth() == TTPT->getDepth()) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+class ForwardingToConstructorVisitor
+ : public RecursiveASTVisitor<ForwardingToConstructorVisitor> {
+public:
+ struct SeenFunctions {
+ unsigned int DepthLeft;
+ SeenFunctions *Prev;
----------------
HighCommander4 wrote:
> IThe "similar place" you linked to my understanding never needs to remove things out of this list. I think this is because they do not branch out in the depth but only have 1 path they follow.
That's a fair point.
I was thinking of this code because it's the implementation of "parameter hint forwarding" -- where we take a call like `make_unique<Point>(1, 2)` and insert `x:` and `y:` parameter hints where the parameter names come from `Point`'s constructor -- and there are conceptual similarities between that feature and what we're implementing. But I guess there are also good reasons for having "branching" behaviour in our feature (we can reference multiple target declarations from a single location) but not in "parameter hint forwarding" (we can only choose one target function whose parameters to forward to a call site).
Note that branching is not fundamentally in conflict with using a set (we could insert a function into the set just before a recursive call, and remove it just after). But again, no need to go to that trouble to avoid a linear traversal of length 10.
https://github.com/llvm/llvm-project/pull/169742
More information about the cfe-commits
mailing list