Skip to content

Commit

Permalink
[CodeComplete] Properly determine qualifiers of 'this' in a lambda
Browse files Browse the repository at this point in the history
Summary:
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.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349655 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ilya-biryukov committed Dec 19, 2018
1 parent c00ce7c commit 30b7031
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3737,11 +3737,9 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,

// 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,
Expand Down
21 changes: 21 additions & 0 deletions test/CodeCompletion/this-quals.cpp
Original file line number Diff line number Diff line change
@@ -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
};
};


0 comments on commit 30b7031

Please sign in to comment.