[clang] [clang] Fix a crash when default argument is passed to an explicit object parameter (PR #177534)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 22 22:46:46 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kartik (hax0kartik)
<details>
<summary>Changes</summary>
This is an invalid usecase and we should mark it as such after outputting a Diagnostic. Fixes #<!-- -->176639.
---
Full diff: https://github.com/llvm/llvm-project/pull/177534.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1)
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1)
- (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+15)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 791212dafd342..4cd25b767320a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -173,6 +173,7 @@ Bug Fixes to Attribute Support
Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed a crash when instantiating ``requires`` expressions involving substitution failures in C++ concepts. (#GH176402)
+- Fixed a crash when a default argument is passed to an explicit object parameter. (#GH176639)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c96189172a010..5837ecd6b9163 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11600,6 +11600,7 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator &D,
Diag(ExplicitObjectParam->getLocation(),
diag::err_explicit_object_default_arg)
<< ExplicitObjectParam->getSourceRange();
+ D.setInvalidType();
}
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index a9e31c3d06676..99f41bbc99020 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1400,3 +1400,18 @@ a void Bar(this int) { // expected-note {{candidate function}}
}
}
+
+namespace GH176639 {
+
+struct S {
+ void operator()(this S =) // expected-error {{the explicit object parameter cannot have a default argument}}
+ // expected-error at -1 {{expected ';' at end of declaration list}}
+ // expected-error at -2 {{expected expression}}
+};
+
+void foo() {
+ S s{};
+ s(0); // expected-error {{no matching function for call to object of type 'S'}}
+}
+
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/177534
More information about the cfe-commits
mailing list