[clang] 7332713 - [Clang] prevent null explicit object argument from being deduced (#104328)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 10:47:20 PDT 2024
Author: Oleksandr T.
Date: 2024-08-15T19:47:14+02:00
New Revision: 7332713b8eea9bb84d8481376f62b8de7c0ddb3a
URL: https://github.com/llvm/llvm-project/commit/7332713b8eea9bb84d8481376f62b8de7c0ddb3a
DIFF: https://github.com/llvm/llvm-project/commit/7332713b8eea9bb84d8481376f62b8de7c0ddb3a.diff
LOG: [Clang] prevent null explicit object argument from being deduced (#104328)
Fixes #102025
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4872dbb7a556ad..5ba9fcb040e3a6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -257,6 +257,7 @@ Bug Fixes to C++ Support
- Properly reject defaulted relational operators with invalid types for explicit object parameters,
e.g., ``bool operator==(this int, const Foo&)`` (#GH100329), and rvalue reference parameters.
- Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter.
+- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index ec951d5ac06dbc..fc883e423f4710 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
ParamTypesForArgChecking.push_back(ParamType);
if (ParamIdx == 0 && HasExplicitObject) {
+ if (ObjectType.isNull())
+ return TemplateDeductionResult::InvalidExplicitArguments;
+
if (auto Result = DeduceCallArgument(ParamType, 0,
/*ExplicitObjectArgument=*/true);
Result != TemplateDeductionResult::Success)
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 23fb383fb73cbb..bfcc5991cee5ac 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1011,3 +1011,22 @@ struct X;
static_assert(__is_same(X<B{0}>, X<B{0}>));
static_assert(!__is_same(X<B{0}>, X<B{1}>));
} // namespace defaulted_compare
+
+namespace GH102025 {
+struct Foo {
+ template <class T>
+ constexpr auto operator[](this T &&self, auto... i) // expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}}
+ -> decltype(_evaluate(self, i...)) {
+ return self._evaluate(i...);
+ }
+
+private:
+ template <class T>
+ constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...));
+};
+
+int main() {
+ Foo foo;
+ return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}}
+}
+}
More information about the cfe-commits
mailing list