@@ -197,6 +197,9 @@ class ResultBuilder {
197197 // / Whether the \p ObjectTypeQualifiers field is active.
198198 bool HasObjectTypeQualifiers;
199199
200+ // Whether the member function is using an explicit object parameter
201+ bool IsExplicitObjectMemberFunction;
202+
200203 // / The selector that we prefer.
201204 Selector PreferredSelector;
202205
@@ -218,8 +221,8 @@ class ResultBuilder {
218221 LookupFilter Filter = nullptr )
219222 : SemaRef(SemaRef), Allocator(Allocator), CCTUInfo(CCTUInfo),
220223 Filter(Filter), AllowNestedNameSpecifiers(false ),
221- HasObjectTypeQualifiers(false ), CompletionContext(CompletionContext ),
222- ObjCImplementation(nullptr ) {
224+ HasObjectTypeQualifiers(false ), IsExplicitObjectMemberFunction( false ),
225+ CompletionContext(CompletionContext), ObjCImplementation(nullptr ) {
223226 // If this is an Objective-C instance method definition, dig out the
224227 // corresponding implementation.
225228 switch (CompletionContext.getKind ()) {
@@ -275,6 +278,10 @@ class ResultBuilder {
275278 HasObjectTypeQualifiers = true ;
276279 }
277280
281+ void setExplicitObjectMemberFn (bool IsExplicitObjectFn) {
282+ IsExplicitObjectMemberFunction = IsExplicitObjectFn;
283+ }
284+
278285 // / Set the preferred selector.
279286 // /
280287 // / When an Objective-C method declaration result is added, and that
@@ -1428,14 +1435,13 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
14281435
14291436 AdjustResultPriorityForDecl (R);
14301437
1431- if (isa<FieldDecl>(R.Declaration )) {
1438+ if (IsExplicitObjectMemberFunction &&
1439+ R.Kind == CodeCompletionResult::RK_Declaration &&
1440+ (isa<CXXMethodDecl>(R.Declaration ) || isa<FieldDecl>(R.Declaration ))) {
14321441 // If result is a member in the context of an explicit-object member
14331442 // function, drop it because it must be accessed through the object
14341443 // parameter
1435- if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(CurContext);
1436- MethodDecl && MethodDecl->isExplicitObjectMemberFunction ()) {
1437- return ;
1438- }
1444+ return ;
14391445 }
14401446
14411447 if (HasObjectTypeQualifiers)
@@ -4646,12 +4652,19 @@ void SemaCodeCompletion::CodeCompleteOrdinaryName(
46464652 break ;
46474653 }
46484654
4649- // If we are in a C++ non-static member function, check the qualifiers on
4650- // the member function to filter/prioritize the results list.
46514655 auto ThisType = SemaRef.getCurrentThisType ();
4652- if (!ThisType.isNull ())
4656+ if (ThisType.isNull ()) {
4657+ // check if function scope is an explicit object function
4658+ if (auto *MethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(
4659+ SemaRef.getCurFunctionDecl ()))
4660+ Results.setExplicitObjectMemberFn (
4661+ MethodDecl->isExplicitObjectMemberFunction ());
4662+ } else {
4663+ // If we are in a C++ non-static member function, check the qualifiers on
4664+ // the member function to filter/prioritize the results list.
46534665 Results.setObjectTypeQualifiers (ThisType->getPointeeType ().getQualifiers (),
46544666 VK_LValue);
4667+ }
46554668
46564669 CodeCompletionDeclConsumer Consumer (Results, SemaRef.CurContext );
46574670 SemaRef.LookupVisibleDecls (S, SemaRef.LookupOrdinaryName , Consumer,
0 commit comments