From: Ilya Biryukov Date: Wed, 19 Dec 2018 18:01:24 +0000 (+0000) Subject: [CodeComplete] Properly determine qualifiers of 'this' in a lambda X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30b70311b7df6275c2bb89844bae45e37977dca2;p=clang [CodeComplete] Properly determine qualifiers of 'this' in a lambda 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 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 773dd46ac4..f8d4e4bb0e 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -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(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, diff --git a/test/CodeCompletion/this-quals.cpp b/test/CodeCompletion/this-quals.cpp new file mode 100644 index 0000000000..eeaed00aa8 --- /dev/null +++ b/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 + }; +}; + +