================ @@ -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()) { ---------------- zyn0217 wrote:
can we avoid the expensive `getCalleeDecl()` for dependent cases? ```cpp if (!isTypeDependent()) { if (const auto *Method = dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl()); Method && Method->isExplicitObjectMemberFunction()) ... } ``` https://github.com/llvm/llvm-project/pull/126868 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits