Skip to content

Commit a156972

Browse files
[clang][AST] Handle implicit first argument in CallExpr::getBeginLoc()
1 parent 17b4cac commit a156972

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ Bug Fixes in This Version
398398
399399
#if 1 ? 1 : 999999999999999999999
400400
#endif
401+
- Fixed a clang 20 regression where diagnostics attached to some calls to member functions
402+
using C++23 "deducing this" did not have a diagnostic location (#GH135522)
401403

402404
Bug Fixes to Compiler Builtins
403405
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Expr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,11 @@ SourceLocation CallExpr::getBeginLoc() const {
16521652
if (!isTypeDependent()) {
16531653
if (const auto *Method =
16541654
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
1655-
Method && Method->isExplicitObjectMemberFunction())
1656-
return getArg(0)->getBeginLoc();
1655+
Method && Method->isExplicitObjectMemberFunction()) {
1656+
if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
1657+
return FirstArgLoc;
1658+
}
1659+
}
16571660
}
16581661

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

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,3 +1134,10 @@ struct S {
11341134
static_assert((S{} << 11) == a);
11351135
// expected-error@-1 {{use of undeclared identifier 'a'}}
11361136
}
1137+
1138+
namespace GH135522 {
1139+
struct S {
1140+
auto f(this auto) -> S;
1141+
bool g() { return f(); } // expected-error {{no viable conversion from returned value of type 'S' to function return type 'bool'}}
1142+
};
1143+
}

0 commit comments

Comments
 (0)