[clang][CodeComplete] Perform approximate member search in bases

Differential Revision: https://reviews.llvm.org/D117037
This commit is contained in:
Kadir Cetinkaya 2022-01-11 18:55:53 +01:00
parent 57e714bcc8
commit 612f5ed882
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
2 changed files with 25 additions and 4 deletions

View File

@ -5519,11 +5519,17 @@ QualType getApproximateType(const Expr *E) {
: getApproximateType(CDSME->getBase());
if (CDSME->isArrow() && !Base.isNull())
Base = Base->getPointeeType(); // could handle unique_ptr etc here?
RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
auto *RD = Base.isNull()
? nullptr
: llvm::dyn_cast<CXXRecordDecl>(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();
// Look up member heuristically, including in bases.
for (const auto *Member : RD->lookupDependentName(
CDSME->getMember(), [](const NamedDecl *Member) {
return llvm::isa<ValueDecl>(Member);
})) {
return llvm::cast<ValueDecl>(Member)->getType().getNonReferenceType();
}
}
}
return Unresolved;

View File

@ -296,3 +296,18 @@ void fooDependent(T t) {
}
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:295:17 %s -o - | FileCheck -check-prefix=CHECK-OVERLOAD %s
// CHECK-OVERLOAD: [#int#]member
struct Base4 {
Base4 base4();
};
template <typename T>
struct Derived2 : Base4 {};
template <typename T>
void testMembersFromBasesInDependentContext() {
Derived2<T> X;
(void)X.base4().base4();
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
// CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
}