[PATCH] D131091: [clang][index] Index unresolved member expression as reference
Denis Fatkulin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 4 12:58:13 PDT 2022
denis-fatkulin updated this revision to Diff 450111.
denis-fatkulin added a comment.
clangd unit test fixed
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131091/new/
https://reviews.llvm.org/D131091
Files:
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp
clang/test/Index/Core/index-dependent-source.cpp
clang/unittests/Index/IndexTests.cpp
Index: clang/unittests/Index/IndexTests.cpp
===================================================================
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -392,6 +392,36 @@
Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
WrittenAt(Position(4, 16))))));
}
+
+TEST(IndexTest, UnresolvedLookupExpr) {
+ std::string Code = R"cpp(
+ template <typename T> void foo(T t);
+ template <typename T> void test(T t) {
+ foo(t);
+ }
+ )cpp";
+ auto Index = std::make_shared<Indexer>();
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code);
+ EXPECT_THAT(Index->Symbols,
+ Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 7)))));
+}
+
+TEST(IndexTest, UnresolvedMemberExpr) {
+ std::string Code = R"cpp(
+ struct Foo {
+ template <typename T> void bar(T t);
+ };
+ template <typename T> void test(Foo F, T t) {
+ F.bar(t);
+ }
+ )cpp";
+ auto Index = std::make_shared<Indexer>();
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code);
+ EXPECT_THAT(Index->Symbols,
+ Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(6, 9)))));
+}
} // namespace
} // namespace index
} // namespace clang
Index: clang/test/Index/Core/index-dependent-source.cpp
===================================================================
--- clang/test/Index/Core/index-dependent-source.cpp
+++ clang/test/Index/Core/index-dependent-source.cpp
@@ -231,3 +231,12 @@
foo<T>();
// CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1
}
+
+struct Foo {
+ template <typename T> void bar();
+ // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | c:@S at Foo@FT@>1#Tbar#v# | <no-cgname> | Decl,RelChild | rel: 1
+};
+template <typename T> void baz(Foo f) {
+ f.bar<T>();
+ // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S at Foo@FT@>1#Tbar#v# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1
+}
Index: clang/lib/Index/IndexBody.cpp
===================================================================
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -468,7 +468,7 @@
return true;
}
- bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+ bool VisitOverloadExpr(OverloadExpr *E) {
SmallVector<SymbolRelation, 4> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
for (auto *D : E->decls())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2090,6 +2090,14 @@
[[f^oo]](s);
}
)cpp",
+ R"cpp(// unresolved member expression
+ struct Foo {
+ template <typename T> void $decl[[b^ar]](T t);
+ };
+ template <typename T> void test(Foo F, T t) {
+ F.[[bar]](t);
+ }
+ )cpp",
// Enum base
R"cpp(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131091.450111.patch
Type: text/x-patch
Size: 3202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220804/df3d6a9b/attachment.bin>
More information about the cfe-commits
mailing list