[clang] [clang][AST] Handle dependent representation of call to function with explicit object parameter in CallExpr::getBeginLoc() (PR #126868)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 23:32:11 PST 2025


================
@@ -1645,11 +1645,21 @@ SourceLocation CallExpr::getBeginLoc() const {
   if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
     return OCE->getBeginLoc();
 
+  // A non-dependent call to a member function with an explicit object parameter
+  // is modelled with the object expression being the first argument, e.g. in
+  // `o.f(x)`, the callee will be just `f`, and `o` will be the first argument.
+  // Since the first argument is written before the callee, the expression's
+  // begin location should come from the first argument.
+  // This does not apply to dependent calls, which are modelled with `o.f`
+  // being the callee.
   if (const auto *Method =
           dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
-      Method && Method->isExplicitObjectMemberFunction()) {
-    assert(getNumArgs() > 0 && getArg(0));
-    return getArg(0)->getBeginLoc();
+      Method && Method->isExplicitObjectMemberFunction() &&
+      !isTypeDependent()) {
----------------
HighCommander4 wrote:

Done, thanks for the suggestion

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


More information about the cfe-commits mailing list