Skip to content

Commit d6c4f88

Browse files
[clang][AST] Remove HasFirstArg assertion in CallExpr::getBeginLoc()
There are cases where the assertion legitimately does not hold (e.g. CallExpr::CreateTemporary()), and there's no readily available way to tell such cases apart. Fixes #130272
1 parent 1fe702f commit d6c4f88

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ Bug Fixes to C++ Support
304304
- Correctly diagnoses template template paramters which have a pack parameter
305305
not in the last position.
306306
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
307+
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
307308

308309
Bug Fixes to AST Handling
309310
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Expr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,9 +1656,11 @@ SourceLocation CallExpr::getBeginLoc() const {
16561656
if (const auto *Method =
16571657
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
16581658
Method && Method->isExplicitObjectMemberFunction()) {
1659-
bool HasFirstArg = getNumArgs() > 0 && getArg(0);
1660-
assert(HasFirstArg);
1661-
if (HasFirstArg)
1659+
// Note: while we typically expect the call to have a first argument
1660+
// here, we can't assert it because in some cases it does not, e.g.
1661+
// calls created with CallExpr::CreateTemporary() during overload
1662+
// resolution.
1663+
if (getNumArgs() > 0 && getArg(0))
16621664
return getArg(0)->getBeginLoc();
16631665
}
16641666
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ struct S {
2626
// CHECK-NEXT: `-DeclRefExpr 0x{{[^ ]*}} <col:5> 'S<T>' lvalue ParmVar 0x{{[^ ]*}} 's' 'S<T>'
2727
};
2828
}
29+
30+
namespace GH130272 {
31+
struct A {};
32+
struct B {
33+
operator A(this B);
34+
};
35+
A a = A(B{});
36+
// CHECK: CallExpr 0x{{[^ ]*}} <col:9, col:11> 'A':'GH130272::A'
37+
}

0 commit comments

Comments
 (0)