[clang-tools-extra] [Clangd] Don't traverse ConceptDecl in typeForNode (PR #191654)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 12 23:20:09 PDT 2026
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/191654
>From 454441f62f167bb4808d8e069b48f3076e1cc023 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Sun, 12 Apr 2026 02:27:40 +0800
Subject: [PATCH] [Clangd] Don't traverse ConceptDecl in typeForNode
ConceptDecl doesn't have an associated template declaration, and it
doesn't introduce a type either.
---
clang-tools-extra/clangd/XRefs.cpp | 5 ++++-
clang-tools-extra/clangd/unittests/XRefsTests.cpp | 9 +++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 4b685b7bf793e..5f64f01c1ff34 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -2058,7 +2058,10 @@ static QualType typeForNode(const ASTContext &Ctx, const HeuristicResolver *H,
}
// Look inside templates.
QualType VisitTemplateDecl(const TemplateDecl *D) {
- return Visit(D->getTemplatedDecl());
+ if (const auto *TD = D->getTemplatedDecl())
+ return Visit(TD);
+ // ConceptDecl doesn't have any associated templates nor types.
+ return QualType();
}
} V(Ctx);
return V.Visit(D);
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 8e97db7ab17c5..00ead63050c8d 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2094,14 +2094,19 @@ TEST(FindType, All) {
TEST(FindType, Definition) {
Annotations A(R"cpp(
class $decl[[X]];
- X *^x;
+ X *$x^x;
class $def[[X]] {};
+
+ template <class T>
+ concept $Concept^True = true;
)cpp");
auto TU = TestTU::withCode(A.code().str());
+ TU.ExtraArgs.push_back("-std=c++20");
ParsedAST AST = TU.build();
- EXPECT_THAT(findType(AST, A.point(), nullptr),
+ EXPECT_THAT(findType(AST, A.point("x"), nullptr),
ElementsAre(sym("X", A.range("decl"), A.range("def"))));
+ EXPECT_THAT(findType(AST, A.point("Concept"), nullptr), IsEmpty());
}
TEST(FindType, Index) {
More information about the cfe-commits
mailing list