summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/unittests/FindTargetTests.cpp')
-rw-r--r--clang-tools-extra/clangd/unittests/FindTargetTests.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 9c1020b7a18..ae16c608fd3 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -589,12 +589,21 @@ protected:
auto *TestDecl = &findDecl(AST, "foo");
if (auto *T = llvm::dyn_cast<FunctionTemplateDecl>(TestDecl))
TestDecl = T->getTemplatedDecl();
- auto &Func = llvm::cast<FunctionDecl>(*TestDecl);
std::vector<ReferenceLoc> Refs;
- findExplicitReferences(Func.getBody(), [&Refs](ReferenceLoc R) {
- Refs.push_back(std::move(R));
- });
+ if (const auto *Func = llvm::dyn_cast<FunctionDecl>(TestDecl))
+ findExplicitReferences(Func->getBody(), [&Refs](ReferenceLoc R) {
+ Refs.push_back(std::move(R));
+ });
+ else if (const auto *NS = llvm::dyn_cast<NamespaceDecl>(TestDecl))
+ findExplicitReferences(NS, [&Refs, &NS](ReferenceLoc R) {
+ // Avoid adding the namespace foo decl to the results.
+ if (R.Targets.size() == 1 && R.Targets.front() == NS)
+ return;
+ Refs.push_back(std::move(R));
+ });
+ else
+ ADD_FAILURE() << "Failed to find ::foo decl for test";
auto &SM = AST.getSourceManager();
llvm::sort(Refs, [&](const ReferenceLoc &L, const ReferenceLoc &R) {
@@ -984,7 +993,24 @@ TEST_F(FindExplicitReferencesTest, All) {
}
)cpp",
"0: targets = {Test}\n"
- "1: targets = {a}, decl\n"}};
+ "1: targets = {a}, decl\n"},
+ // unknown template name should not crash.
+ // duplicate $1$2 is fixed on master.
+ {R"cpp(
+ template <template <typename> typename T>
+ struct Base {};
+ namespace foo {
+ template <typename $0^T>
+ struct $1^$2^Derive : $3^Base<$4^T::template $5^Unknown> {};
+ }
+ )cpp",
+ "0: targets = {foo::Derive::T}, decl\n"
+ "1: targets = {foo::Derive}, decl\n"
+ "2: targets = {foo::Derive}, decl\n"
+ "3: targets = {Base}\n"
+ "4: targets = {foo::Derive::T}\n"
+ "5: targets = {}, qualifier = 'T::'\n"},
+ };
for (const auto &C : Cases) {
llvm::StringRef ExpectedCode = C.first;
OpenPOWER on IntegriCloud