Skip to content

[clang][AST] Handle implicit first argument in CallExpr::getBeginLoc() #135757

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 2 commits into from
Apr 15, 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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ Bug Fixes in This Version
- ``#embed`` directive now diagnoses use of a non-character file (device file)
such as ``/dev/urandom`` as an error. This restriction may be relaxed in the
future. See (#GH126629).
- Fixed a clang 20 regression where diagnostics attached to some calls to member functions
using C++23 "deducing this" did not have a diagnostic location (#GH135522)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,11 @@ SourceLocation CallExpr::getBeginLoc() const {
if (!isTypeDependent()) {
if (const auto *Method =
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
Method && Method->isExplicitObjectMemberFunction())
return getArg(0)->getBeginLoc();
Method && Method->isExplicitObjectMemberFunction()) {
if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I took the approach of falling through if FirstArgLoc is invalid for any reason; presumably we never want to return an invalid location when we might fall through to a valid one in getCallee()->getBeginLoc().

We could alternatively make the check more specific, to e.g. !getArg(0)->isImplicitCXXThis().

return FirstArgLoc;
}
}
}

SourceLocation begin = getCallee()->getBeginLoc();
Expand Down
7 changes: 7 additions & 0 deletions clang/test/SemaCXX/cxx2b-deducing-this.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,3 +1134,10 @@ struct S {
static_assert((S{} << 11) == a);
// expected-error@-1 {{use of undeclared identifier 'a'}}
}

namespace GH135522 {
struct S {
auto f(this auto) -> S;
bool g() { return f(); } // expected-error {{no viable conversion from returned value of type 'S' to function return type 'bool'}}
};
}
Loading