https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/148807
>From 25d5589b47b39779958c94011814cb68fd7ea374 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Tue, 15 Jul 2025 11:06:03 +0200 Subject: [PATCH] [Clang] Remove explicit object from non member function. To avoid crashing later (as we assume only member functions can have explicit parameters) Fixes #113185 --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaType.cpp | 4 +++- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e8c85483e9864..40213cd103c43 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -953,6 +953,7 @@ Bug Fixes to C++ Support - Fix a bug where private access specifier of overloaded function not respected. (#GH107629) - Correctly handles calling an explicit object member function template overload set through its address (``(&Foo::bar<baz>)()``). +- Fix a crash when using an explicit object parameter in a non-member function. (#GH113185) - Fix a crash when forming an invalid call to an operator with an explicit object member. (#GH147121) - Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820) - Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 661746731fdcc..bb114aff2366b 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -4860,7 +4860,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, S.Diag(First->getBeginLoc(), diag::err_explicit_object_parameter_invalid) << First->getSourceRange(); - + // Do let non-member function have explicit parameters + // to not break assumptions elsewhere in the code. + First->setExplicitObjectParameterLoc(SourceLocation()); D.setInvalidType(); AreDeclaratorChunksValid = false; } diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 6987d0c020457..2253cbb26285e 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -1347,3 +1347,13 @@ int main() { // expected-note@#S3-f-cand2 {{candidate function not viable: no known conversion from 'S3' to 'int' for object argument}} } } + +namespace GH113185 { + +void Bar(this int) { // expected-note {{candidate function}} + // expected-error@-1 {{an explicit object parameter cannot appear in a non-member function}} + Bar(0); + Bar(); // expected-error {{no matching function for call to 'Bar'}} +} + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits