[clang] 612f5ed - [clang][CodeComplete] Perform approximate member search in bases

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 12 01:57:32 PST 2022


Author: Kadir Cetinkaya
Date: 2022-01-12T10:56:06+01:00
New Revision: 612f5ed8823120b30cb3c8bbde79a7f0ae9d1761

URL: https://github.com/llvm/llvm-project/commit/612f5ed8823120b30cb3c8bbde79a7f0ae9d1761
DIFF: https://github.com/llvm/llvm-project/commit/612f5ed8823120b30cb3c8bbde79a7f0ae9d1761.diff

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

Differential Revision: https://reviews.llvm.org/D117037

Added: 
    

Modified: 
    clang/lib/Sema/SemaCodeComplete.cpp
    clang/test/CodeCompletion/member-access.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 9266deb6699af..cc08dee266136 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -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;

diff  --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp
index 88129d45bccf1..2c611b4715800 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -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
+}


        


More information about the cfe-commits mailing list