ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.

The clang used to pick up the qualifiers of the lamba's call operator
(which is always const) and fail to show non-const methods of 'this' in
completion results.


Repository:
  rC Clang

https://reviews.llvm.org/D55885

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/this-quals.cpp


Index: test/CodeCompletion/this-quals.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/this-quals.cpp
@@ -0,0 +1,21 @@
+class foo {
+  void mut_func() {
+    [this]() {
+
+    }();
+    // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:1 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
+    // CHECK-CC1: const_func
+    // CHECK-CC1: mut_func
+  }
+
+  void const_func() const {
+    [this]() {
+
+    }();
+    // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:1 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
+    // CHECK-CC2-NOT: mut_func
+    // CHECK-CC2: const_func
+  };
+};
+
+
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3737,11 +3737,9 @@
 
   // If we are in a C++ non-static member function, check the qualifiers on
   // the member function to filter/prioritize the results list.
-  if (CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext)) {
-    if (CurMethod->isInstance()) {
-      Results.setObjectTypeQualifiers(CurMethod->getTypeQualifiers());
-    }
-  }
+  auto ThisType = getCurrentThisType();
+  if (!ThisType.isNull())
+    
Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers());
 
   CodeCompletionDeclConsumer Consumer(Results, CurContext);
   LookupVisibleDecls(S, LookupOrdinaryName, Consumer,


Index: test/CodeCompletion/this-quals.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/this-quals.cpp
@@ -0,0 +1,21 @@
+class foo {
+  void mut_func() {
+    [this]() {
+
+    }();
+    // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:1 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+    // CHECK-CC1: const_func
+    // CHECK-CC1: mut_func
+  }
+
+  void const_func() const {
+    [this]() {
+
+    }();
+    // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:1 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+    // CHECK-CC2-NOT: mut_func
+    // CHECK-CC2: const_func
+  };
+};
+
+
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3737,11 +3737,9 @@
 
   // If we are in a C++ non-static member function, check the qualifiers on
   // the member function to filter/prioritize the results list.
-  if (CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext)) {
-    if (CurMethod->isInstance()) {
-      Results.setObjectTypeQualifiers(CurMethod->getTypeQualifiers());
-    }
-  }
+  auto ThisType = getCurrentThisType();
+  if (!ThisType.isNull())
+    Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers());
 
   CodeCompletionDeclConsumer Consumer(Results, CurContext);
   LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to