[PATCH] D68335: [CodeComplete] Ensure object is the same in compareOverloads()

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 06:48:33 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.

This fixes a regression that led to size() not being available in clangd
when completing 'deque().^'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68335

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access-qualifiers.cpp


Index: clang/test/CodeCompletion/member-access-qualifiers.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeCompletion/member-access-qualifiers.cpp
@@ -0,0 +1,13 @@
+struct deque_base {
+  int &size();
+  const int &size() const;
+};
+
+struct deque : private deque_base {
+    int size() const;
+};
+
+auto x = deque().
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:18 %s -o - | FileCheck %s
+// CHECK: COMPLETION: size : [#int#]size()[# const#]
+// CHECK: COMPLETION: size (Hidden,InBase,Inaccessible) : [#int &#]deque_base::size()
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1185,6 +1185,9 @@
                                         const CXXMethodDecl &Incumbent,
                                         const Qualifiers &ObjectQuals,
                                         ExprValueKind ObjectKind) {
+  // This function does not take object type into account.
+  if (Candidate.getDeclContext() != Incumbent.getDeclContext())
+    return OverloadCompare::BothViable;
   if (Candidate.isVariadic() != Incumbent.isVariadic() ||
       Candidate.getNumParams() != Incumbent.getNumParams() ||
       Candidate.getMinRequiredArguments() !=
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2546,6 +2546,25 @@
               UnorderedElementsAre(AllOf(Qualifier(""), Named("ABCDE"))));
 }
 
+TEST(CompletionTest, DerivedMethodsAreAlwaysVisible) {
+  // Despite the fact that base method matches the ref-qualifier better,
+  // completion results should only include the derived method.
+  auto Completions = completions(R"cpp(
+    struct deque_base {
+      int &size();
+      const int &size() const;
+    };
+    struct deque : deque_base {
+        int size() const;
+    };
+
+    auto x = deque().^
+  )cpp")
+                         .Completions;
+  EXPECT_THAT(Completions,
+              ElementsAre(AllOf(ReturnType("int"), Named("size"))));
+}
+
 TEST(NoCompileCompletionTest, Basic) {
   auto Results = completionsNoCompile(R"cpp(
     void func() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68335.222821.patch
Type: text/x-patch
Size: 2395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191002/d97dd52c/attachment.bin>


More information about the cfe-commits mailing list