[clang] [clang-tools-extra] [clangd] Autocomplete fixes for methods (PR #165916)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 23:07:21 PST 2026
================
@@ -6860,12 +6966,19 @@ void SemaCodeCompletion::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
// resolves to a dependent record.
DeclContext *Ctx = SemaRef.computeDeclContext(SS, /*EnteringContext=*/true);
+ std::optional<Sema::ContextRAII> SavedContext;
+ // When completing a definition, simulate that we are in class scope to access
+ // private methods.
+ if (IsInDeclarationContext && Ctx != nullptr)
+ SavedContext.emplace(SemaRef, Ctx);
----------------
HighCommander4 wrote:
Very clever :)
Not being super familiar with Sema internals, it feels a bit scary to be messing with `Sema::CurContext`... but I think it should be fine based on the following:
* Lots of other Sema code is using `ContextRAII`, so I figure it doesn't have side effects that persist beyond the scope of the RAII object
* While the object is on the stack, any unexpected effects should be limited to the completions we get in declaration context, which were wrong to begin with
(No change needed, just writing down my reasoning for why I believe this is ok to do.)
https://github.com/llvm/llvm-project/pull/165916
More information about the cfe-commits
mailing list