[PATCH] D117037: [clang][CodeComplete] Perform approximate member search in bases
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 11 09:56:27 PST 2022
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117037
Files:
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5411,9 +5411,21 @@
Base = Base->getPointeeType(); // could handle unique_ptr etc here?
RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
if (RD && RD->isCompleteDefinition()) {
- for (const auto *Member : RD->lookup(CDSME->getMember()))
- if (const ValueDecl *VD = llvm::dyn_cast<ValueDecl>(Member))
- return VD->getType().getNonReferenceType();
+ // For c++ records perform a dependent name lookup, which also takes care
+ // of the bases.
+ if (auto *CXXRD = llvm::dyn_cast<CXXRecordDecl>(RD)) {
+ for (const auto *Member : CXXRD->lookupDependentName(
+ CDSME->getMember(), [](const NamedDecl *Member) {
+ return llvm::isa<ValueDecl>(Member);
+ })) {
+ return llvm::cast<ValueDecl>(Member)->getType().getNonReferenceType();
+ }
+ } else {
+ for (const auto *Member : RD->lookup(CDSME->getMember())) {
+ if (const ValueDecl *VD = llvm::dyn_cast<ValueDecl>(Member))
+ return VD->getType().getNonReferenceType();
+ }
+ }
}
}
return Unresolved;
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3453,6 +3453,19 @@
}
}
+TEST(CompletionTest, UndeducedType) {
+ clangd::CodeCompleteOptions Opts;
+ const std::string Code = R"cpp(
+struct Base { Base foo(); };
+
+template <typename T> struct Foo : Base {
+ void bar() { this->foo().^foo(); }
+};
+ )cpp";
+
+ EXPECT_THAT(completions(Code, {}, Opts).Completions,
+ Contains(Labeled("foo()")));
+}
} // namespace
} // namespace clangd
} // namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117037.398996.patch
Type: text/x-patch
Size: 2026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220111/8776a259/attachment-0001.bin>
More information about the cfe-commits
mailing list