[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
Mon Dec 22 22:47:13 PST 2025
================
@@ -666,9 +712,20 @@ bool SymbolCollector::handleDeclOccurrence(
auto FileLoc = SM.getFileLoc(Loc);
auto FID = SM.getFileID(FileLoc);
if (Opts.RefsInHeaders || FID == SM.getMainFileID()) {
+ auto *Container = getRefContainer(ASTNode.Parent, Opts);
addRef(ID, SymbolRef{FileLoc, FID, Roles, index::getSymbolInfo(ND).Kind,
- getRefContainer(ASTNode.Parent, Opts),
- isSpelled(FileLoc, *ND)});
+ Container, isSpelled(FileLoc, *ND)});
+ // Also collect indirect constructor calls like `make_unique`
+ for (auto *Constructor : findIndirectConstructors(ASTNode.OrigD)) {
+ if (!shouldCollectSymbol(*Constructor, *ASTCtx, Opts,
+ CheckIsMainFileOnly(Constructor)))
+ continue;
+ if (auto ConstructorID = getSymbolIDCached(Constructor))
+ addRef(ConstructorID,
+ SymbolRef{FileLoc, FID, Roles,
+ index::getSymbolInfo(Constructor).Kind, Container,
+ isSpelled(FileLoc, *Constructor)});
----------------
HighCommander4 wrote:
Looking at this again, the `Spelled` field of `SymbolRef` signifies whether the referenced symbol's name is explicitly written at the location of the reference. In the case of indirect constructors, that's by definition not the case, so we can just pass `false`.
https://github.com/llvm/llvm-project/pull/169742
More information about the cfe-commits
mailing list