1
- // ===-- FindSymbolsTests .cpp -------------------------*- C++ -*------------===//
1
+ // ===-- FindTargetTests .cpp - -------------------------*- C++ -*------------===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
@@ -553,8 +553,8 @@ class FindExplicitReferencesTest : public ::testing::Test {
553
553
std::string DumpedReferences;
554
554
};
555
555
556
- // / Parses \p Code, finds function '::foo' and annotates its body with results
557
- // / of findExplicitReferecnces.
556
+ // / Parses \p Code, finds function or namespace '::foo' and annotates its body
557
+ // / with results of findExplicitReferecnces.
558
558
// / See actual tests for examples of annotation format.
559
559
AllRefs annotateReferencesInFoo (llvm::StringRef Code) {
560
560
TestTU TU;
@@ -574,12 +574,21 @@ class FindExplicitReferencesTest : public ::testing::Test {
574
574
auto *TestDecl = &findDecl (AST, " foo" );
575
575
if (auto *T = llvm::dyn_cast<FunctionTemplateDecl>(TestDecl))
576
576
TestDecl = T->getTemplatedDecl ();
577
- auto &Func = llvm::cast<FunctionDecl>(*TestDecl);
578
577
579
578
std::vector<ReferenceLoc> Refs;
580
- findExplicitReferences (Func.getBody (), [&Refs](ReferenceLoc R) {
581
- Refs.push_back (std::move (R));
582
- });
579
+ if (const auto *Func = llvm::dyn_cast<FunctionDecl>(TestDecl))
580
+ findExplicitReferences (Func->getBody (), [&Refs](ReferenceLoc R) {
581
+ Refs.push_back (std::move (R));
582
+ });
583
+ else if (const auto *NS = llvm::dyn_cast<NamespaceDecl>(TestDecl))
584
+ findExplicitReferences (NS, [&Refs, &NS](ReferenceLoc R) {
585
+ // Avoid adding the namespace foo decl to the results.
586
+ if (R.Targets .size () == 1 && R.Targets .front () == NS)
587
+ return ;
588
+ Refs.push_back (std::move (R));
589
+ });
590
+ else
591
+ ADD_FAILURE () << " Failed to find ::foo decl for test" ;
583
592
584
593
auto &SM = AST.getSourceManager ();
585
594
llvm::sort (Refs, [&](const ReferenceLoc &L, const ReferenceLoc &R) {
@@ -720,6 +729,25 @@ TEST_F(FindExplicitReferencesTest, All) {
720
729
" 1: targets = {vi}, decl\n "
721
730
" 2: targets = {valias}\n "
722
731
" 3: targets = {vb}, decl\n " },
732
+ // Injected class name.
733
+ {R"cpp(
734
+ namespace foo {
735
+ template <typename $0^T>
736
+ class $1^$2^Bar {
737
+ ~$3^Bar();
738
+ void $4^f($5^Bar);
739
+ };
740
+ }
741
+ )cpp" ,
742
+ " 0: targets = {foo::Bar::T}, decl\n "
743
+ // FIXME: avoid the 2 duplicated foo::Bar references below, the first
744
+ // one comes from ClassTemplateDecl; the second comes from the
745
+ // underlying CXXRecordDecl.
746
+ " 1: targets = {foo::Bar}, decl\n "
747
+ " 2: targets = {foo::Bar}, decl\n "
748
+ " 3: targets = {foo::Bar}\n "
749
+ " 4: targets = {foo::Bar::f}, decl\n "
750
+ " 5: targets = {foo::Bar}\n " },
723
751
// MemberExpr should know their using declaration.
724
752
{R"cpp(
725
753
struct X { void func(int); };
0 commit comments