[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 14 15:45:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Oleksandr T. (a-tarasyuk)
<details>
<summary>Changes</summary>
Fixes #<!-- -->102025
---
Full diff: https://github.com/llvm/llvm-project/pull/104328.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1)
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+3)
- (added) clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp (+30)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1541b0cbf4875c..7acaf4ebdf1f7d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -245,6 +245,7 @@ Bug Fixes to C++ Support
specialization of a conversion function template.
- Correctly diagnose attempts to use a concept name in its own definition;
A concept name is introduced to its scope sooner to match the C++ standard. (#GH55875)
+- 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/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp
new file mode 100644
index 00000000000000..4880b148c53c14
--- /dev/null
+++ b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s
+
+namespace std {
+struct rv {};
+
+template <bool B, typename T> struct enable_if;
+template <typename T> struct enable_if<true, T> { typedef T type; };
+
+template <typename U, typename T>
+typename enable_if<__is_convertible(T, rv), U>::type forward(T &);
+template <typename U, typename T>
+typename enable_if<!__is_convertible(T, rv), U &>::type forward(T &);
+}
+
+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(std::forward<T>(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'}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/104328
More information about the cfe-commits
mailing list