https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/148807
To avoid crashing later (as we assume only member functions can have explicit parameters) Fixes #113185 >From bf204f023a4f84732c5876ff86e7de603fd95aac 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/lib/Sema/SemaType.cpp | 4 +++- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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