Skip to content

Commit a1c57ce

Browse files
[clang][AST] Handle dependent representation of call to function with explicit object parameter in CallExpr::getBeginLoc()
Fixes #126720
1 parent baf7a3c commit a1c57ce

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,8 +1648,11 @@ SourceLocation CallExpr::getBeginLoc() const {
16481648
if (const auto *Method =
16491649
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
16501650
Method && Method->isExplicitObjectMemberFunction()) {
1651-
assert(getNumArgs() > 0 && getArg(0));
1652-
return getArg(0)->getBeginLoc();
1651+
if (!isTypeDependent()) {
1652+
assert(getNumArgs() > 0 && getArg(0));
1653+
if (getNumArgs() > 0 && getArg(0))
1654+
return getArg(0)->getBeginLoc();
1655+
}
16531656
}
16541657

16551658
SourceLocation begin = getCallee()->getBeginLoc();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ void main() {
1313
// CHECK-NEXT: | `-DeclRefExpr 0x{{[^ ]*}} <col:13> 'int (S &)' lvalue CXXMethod 0x{{[^ ]*}} 'f' 'int (S &)'
1414
}
1515
}
16+
17+
namespace GH1269720 {
18+
template <typename T>
19+
struct S {
20+
void f(this S&);
21+
void g(S s) {
22+
s.f();
23+
}
24+
// CHECK: CallExpr 0x{{[^ ]*}} <line:22:5, col:9> '<dependent type>'
25+
// CHECK-NEXT: `-MemberExpr 0x{{[^ ]*}} <col:5, col:7> '<bound member function type>' .f
26+
// CHECK-NEXT: `-DeclRefExpr 0x{{[^ ]*}} <col:5> 'S<T>' lvalue ParmVar 0x{{[^ ]*}} 's' 'S<T>'
27+
};
28+
}

0 commit comments

Comments
 (0)