[clang] [clang-tools-extra] [clang] Skip suggesting unqualified members in explicit-object member functions (PR #153760)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 16 16:23:40 PDT 2025


================
@@ -1428,6 +1428,16 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
 
   AdjustResultPriorityForDecl(R);
 
+  if (isa<FieldDecl>(R.Declaration)) {
+    // If result is a member in the context of an explicit-object member
+    // function, drop it because it must be accessed through the object
+    // parameter
+    if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(CurContext);
----------------
HighCommander4 wrote:

> Is storing it with a call to `setObjectTypeQualifiers` fine? Or is introducing a new get-set pair better?

I think it would actually make the most sense in an `else` branch of [this `if`](https://searchfox.org/llvm/rev/a293573c4e3e43f9f6279f075c3262ea5dc17086/clang/lib/Sema/SemaCodeComplete.cpp#4642), since `getCurrentThisType()` should return null in an explicit-object member function (due to [this check](https://searchfox.org/llvm/rev/a293573c4e3e43f9f6279f075c3262ea5dc17086/clang/lib/Sema/SemaExprCXX.cpp#1214)) (which suggests using a different get/set pair).

https://github.com/llvm/llvm-project/pull/153760


More information about the cfe-commits mailing list