Skip to content

[clang][AST] Remove HasFirstArg assertion in CallExpr::getBeginLoc() #130725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ Bug Fixes to C++ Support
- Correctly diagnoses template template paramters which have a pack parameter
not in the last position.
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,9 +1656,11 @@ SourceLocation CallExpr::getBeginLoc() const {
if (const auto *Method =
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
Method && Method->isExplicitObjectMemberFunction()) {
bool HasFirstArg = getNumArgs() > 0 && getArg(0);
assert(HasFirstArg);
if (HasFirstArg)
// Note: while we typically expect the call to have a first argument
// here, we can't assert it because in some cases it does not, e.g.
// calls created with CallExpr::CreateTemporary() during overload
// resolution.
if (getNumArgs() > 0 && getArg(0))
return getArg(0)->getBeginLoc();
}
}
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/ast-dump-cxx2b-deducing-this.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ struct S {
// CHECK-NEXT: `-DeclRefExpr 0x{{[^ ]*}} <col:5> 'S<T>' lvalue ParmVar 0x{{[^ ]*}} 's' 'S<T>'
};
}

namespace GH130272 {
struct A {};
struct B {
operator A(this B);
};
A a = A(B{});
// CHECK: CallExpr 0x{{[^ ]*}} <col:9, col:11> 'A':'GH130272::A'
}