Skip to content

Commit

Permalink
[clang][AST] Handle dependent representation of call to function with…
Browse files Browse the repository at this point in the history
… explicit object parameter in CallExpr::getBeginLoc()

Fixes #126720
  • Loading branch information
HighCommander4 committed Feb 12, 2025
1 parent baf7a3c commit a1c57ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,8 +1648,11 @@ SourceLocation CallExpr::getBeginLoc() const {
if (const auto *Method =
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
Method && Method->isExplicitObjectMemberFunction()) {
assert(getNumArgs() > 0 && getArg(0));
return getArg(0)->getBeginLoc();
if (!isTypeDependent()) {
assert(getNumArgs() > 0 && getArg(0));
if (getNumArgs() > 0 && getArg(0))
return getArg(0)->getBeginLoc();
}
}

SourceLocation begin = getCallee()->getBeginLoc();
Expand Down
13 changes: 13 additions & 0 deletions clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ void main() {
// CHECK-NEXT: | `-DeclRefExpr 0x{{[^ ]*}} <col:13> 'int (S &)' lvalue CXXMethod 0x{{[^ ]*}} 'f' 'int (S &)'
}
}

namespace GH1269720 {
template <typename T>
struct S {
void f(this S&);
void g(S s) {
s.f();
}
// CHECK: CallExpr 0x{{[^ ]*}} <line:22:5, col:9> '<dependent type>'
// CHECK-NEXT: `-MemberExpr 0x{{[^ ]*}} <col:5, col:7> '<bound member function type>' .f
// CHECK-NEXT: `-DeclRefExpr 0x{{[^ ]*}} <col:5> 'S<T>' lvalue ParmVar 0x{{[^ ]*}} 's' 'S<T>'
};
}

0 comments on commit a1c57ce

Please sign in to comment.