[PATCH] D86424: [clang] Do not consider the template arguments of bases to be bases themselves
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 1 16:18:34 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7cd6b0c3b5db: [clang] Do not consider the template arguments of bases to be bases themselves (authored by nridge).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86424/new/
https://reviews.llvm.org/D86424
Files:
clang/lib/Index/IndexTypeSourceInfo.cpp
clang/test/Index/Core/index-source.cpp
clang/unittests/Index/IndexTests.cpp
Index: clang/unittests/Index/IndexTests.cpp
===================================================================
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -334,6 +334,20 @@
WrittenAt(Position(3, 20)))));
}
+TEST(IndexTest, RelationBaseOf) {
+ std::string Code = R"cpp(
+ class A {};
+ template <typename> class B {};
+ class C : B<A> {};
+ )cpp";
+ auto Index = std::make_shared<Indexer>();
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code);
+ // A should not be the base of anything.
+ EXPECT_THAT(Index->Symbols,
+ Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference),
+ Not(HasRole(SymbolRole::RelationBaseOf)))));
+}
+
} // namespace
} // namespace index
} // namespace clang
Index: clang/test/Index/Core/index-source.cpp
===================================================================
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -560,3 +560,11 @@
};
}
+
+namespace clangd_issue_504 {
+class A {};
+template <typename> class B {};
+class C : B<A> {};
+// CHECK: [[@LINE-1]]:13 | class/C++ | A | c:@N at clangd_issue_504@S at A | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | C | c:@N at clangd_issue_504@S at C
+} // namespace clangd_issue_504
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===================================================================
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -8,6 +8,7 @@
#include "IndexingContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
+#include "llvm/ADT/ScopeExit.h"
using namespace clang;
using namespace index;
@@ -160,6 +161,26 @@
return true;
}
+ bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
+ if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
+ return false;
+ if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName()))
+ return false;
+
+ // The relations we have to `Parent` do not apply to our template arguments,
+ // so clear them while visiting the args.
+ SmallVector<SymbolRelation, 3> SavedRelations = Relations;
+ Relations.clear();
+ auto ResetSavedRelations =
+ llvm::make_scope_exit([&] { this->Relations = SavedRelations; });
+ for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
+ if (!TraverseTemplateArgumentLoc(TL.getArgLoc(I)))
+ return false;
+ }
+
+ return true;
+ }
+
bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) {
auto *T = TL.getTypePtr();
if (!T)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86424.289308.patch
Type: text/x-patch
Size: 2674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200901/2e437293/attachment.bin>
More information about the cfe-commits
mailing list