Skip to content

Commit d5ef6d5

Browse files
[clang] Compute accurate begin location for CallExpr with explicit object parameter
The explicit object parameter is written before the callee expression, so the begin location should come from the explicit object parameter. Fixes #116335
1 parent 9fde1a4 commit d5ef6d5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,13 @@ SourceLocation CallExpr::getBeginLoc() const {
16391639
if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
16401640
return OCE->getBeginLoc();
16411641

1642+
if (const CXXMethodDecl *Method =
1643+
dyn_cast_or_null<const CXXMethodDecl>(getCalleeDecl());
1644+
Method && Method->isExplicitObjectMemberFunction()) {
1645+
assert(getNumArgs() > 0 && getArg(0));
1646+
return getArg(0)->getBeginLoc();
1647+
}
1648+
16421649
SourceLocation begin = getCallee()->getBeginLoc();
16431650
if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
16441651
begin = getArg(0)->getBeginLoc();

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15565,7 +15565,7 @@ ExprResult Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
1556515565
// Build the actual expression node.
1556615566
ExprResult FnExpr =
1556715567
CreateFunctionRefExpr(*this, Method, FoundDecl, MemExpr,
15568-
HadMultipleCandidates, MemExpr->getBeginLoc());
15568+
HadMultipleCandidates, MemExpr->getExprLoc());
1556915569
if (FnExpr.isInvalid())
1557015570
return ExprError();
1557115571

clang/test/AST/ast-dump-cxx2b-deducing-this.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int main() {
99
S s;
1010
int x = s.f();
1111
// CHECK: CallExpr 0x{{[^ ]*}} <col:11, col:15> 'int
12-
// CHECK-NEXT: |-ImplicitCastExpr 0x{{[^ ]*}} <col:11> 'int (*)(S &)' <FunctionToPointerDecay>
13-
// CHECK-NEXT: | `-DeclRefExpr 0x{{[^ ]*}} <col:11> 'int (S &)' lvalue CXXMethod 0x{{[^ ]*}} 'f' 'int (S &)'
12+
// CHECK-NEXT: |-ImplicitCastExpr 0x{{[^ ]*}} <col:13> 'int (*)(S &)' <FunctionToPointerDecay>
13+
// CHECK-NEXT: | `-DeclRefExpr 0x{{[^ ]*}} <col:13> 'int (S &)' lvalue CXXMethod 0x{{[^ ]*}} 'f' 'int (S &)'
1414
}
1515
}

0 commit comments

Comments
 (0)