[clang] 57d81c2 - [Clang] Remove explicit object from non member function. (#148807)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 15 04:34:36 PDT 2025
Author: Corentin Jabot
Date: 2025-07-15T13:34:32+02:00
New Revision: 57d81c23f4c8d3ad88210aab29f0809974e7d1ce
URL: https://github.com/llvm/llvm-project/commit/57d81c23f4c8d3ad88210aab29f0809974e7d1ce
DIFF: https://github.com/llvm/llvm-project/commit/57d81c23f4c8d3ad88210aab29f0809974e7d1ce.diff
LOG: [Clang] Remove explicit object from non member function. (#148807)
To avoid crashing later (as we assume only member functions can have
explicit object parameters)
Fixes #113185
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp
Removed:
################################################################################
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 at -1 {{an explicit object parameter cannot appear in a non-member function}}
+ Bar(0);
+ Bar(); // expected-error {{no matching function for call to 'Bar'}}
+}
+
+}
More information about the cfe-commits
mailing list