[PATCH] D124486: [clangd] ExtractVariable support for C and Objective-C

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 25 11:00:18 PDT 2022


sammccall added a comment.

Please go ahead and land this, the remaining open comment doesn't really matter.



================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:418
+  if (const auto *ME = dyn_cast<MemberExpr>(E))
+    if (const auto *TE = dyn_cast<CXXThisExpr>(ME->getBase()))
+      if (TE->isImplicit())
----------------
dgoldman wrote:
> sammccall wrote:
> > dgoldman wrote:
> > > sammccall wrote:
> > > > oops, I forgot one detail: we want ME->getBase()->IgnoreImpCasts()
> > > > 
> > > > (in `void nonConstMethod() { constMethod(); }` there's an ImplicitCastExpr in there...
> > > Hmm, is this right, I tested out that example and it seems like that's actually a `CXXMemberCallExpr` which this doesn't handle?
> > The callee of the CXXMemberCallExpr is the MemberExpr i'm talking about here.
> Right but this code here doesn't handle CXXMemberCallExpr, only MemberExpr - so we don't even see the callee here. If I add the following above:
> 
> ```
>   if (const auto *MCE = dyn_cast<CXXMemberCallExpr>(E))
>     E = MCE->getCallee();
> ```
> 
> and do `ME->getBase()->IgnoreImpCasts()` then:
> 
> 
> ```
>     class Test {
>       int constMethod() const { return 1; }
>       int nonConstMethod() { return [[constMethod()]]; }
>     };
> ```
> 
> will be unavailable.
> Right but this code here doesn't handle CXXMemberCallExpr, only MemberExpr - so we don't even see the callee here.

I don't understand what you mean.

If you select `  int nonConstMethod() { return [[constMethod]](); }`, then isn't N such a MemberExpr?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124486/new/

https://reviews.llvm.org/D124486



More information about the cfe-commits mailing list