[clang] [clang-tools-extra] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 16:51:35 PST 2024


================
@@ -1639,11 +1639,19 @@ SourceLocation CallExpr::getBeginLoc() const {
   if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
     return OCE->getBeginLoc();
 
+  if (const auto *Method =
+          dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
----------------
HighCommander4 wrote:

> heh I think there is some opportunities to merge the slightly different if statements (for the explicit and not explicit cases) but it would be a minor improvement so I'll will approve that

Ah, I see.

I considered doing something like this:

```c++
bool UseFirstArgLoc = false;
if (/* is explicit object */)
  UseFirstArgLoc = true;

SourceLocation begin = getCallee()->getBeginLoc();
if ((begin.isInvalid() || UseFirstArgLoc) && getNumArgs() > 0 && getArg(0))
  begin = getArg(0)->getBeginLoc();
return begin;
```
  
But this needlessly evaluates `getCallee()->getBeginLoc()` in the explicit case, so I opted not to do this.

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


More information about the cfe-commits mailing list