[gcc r15-5833] libstdc++: Fix constraints on std::optional converting assignments [PR117858]
Jonathan Wakely
redi@gcc.gnu.org
Sat Nov 30 21:39:44 GMT 2024
https://gcc.gnu.org/g:c2c7d71eeeab7c6e2a8124b53d6eae6c59781e79
commit r15-5833-gc2c7d71eeeab7c6e2a8124b53d6eae6c59781e79
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Nov 30 21:37:02 2024 +0000
libstdc++: Fix constraints on std::optional converting assignments [PR117858]
It looks like I copied these constraints from operator=(U&&) and didn't
correct them to account for the parameter being optional<U> not U.
libstdc++-v3/ChangeLog:
PR libstdc++/117858
* include/std/optional (operator=(const optional<U>&)): Fix copy
and paste error in constraints.
(operator=(optional<U>&&)): Likewise.
* testsuite/20_util/optional/assignment/117858.cc: New test.
Diff:
---
libstdc++-v3/include/std/optional | 4 ++--
.../testsuite/20_util/optional/assignment/117858.cc | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index b8eedeec7817..55e56cfb9ed1 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -1043,7 +1043,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Up>
#ifdef _GLIBCXX_USE_CONSTRAINTS_FOR_OPTIONAL
- requires (!is_same_v<optional, remove_cvref_t<_Up>>)
+ requires (!is_same_v<_Tp, _Up>)
&& is_constructible_v<_Tp, const _Up&>
&& is_assignable_v<_Tp&, const _Up&>
&& (!__converts_from_optional<_Tp, _Up>::value)
@@ -1077,7 +1077,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Up>
#ifdef _GLIBCXX_USE_CONSTRAINTS_FOR_OPTIONAL
- requires (!is_same_v<optional, remove_cvref_t<_Up>>)
+ requires (!is_same_v<_Tp, _Up>)
&& is_constructible_v<_Tp, _Up>
&& is_assignable_v<_Tp&, _Up>
&& (!__converts_from_optional<_Tp, _Up>::value)
diff --git a/libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc b/libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc
new file mode 100644
index 000000000000..9443e1604846
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++17 } }
+
+// PR 117858 std::optional with a constructor template<typename T> ctor(T)
+
+#include <optional>
+
+struct Focus
+{
+ template<class T>
+ Focus(T newValue) { }
+};
+
+void g(std::optional<Focus> f)
+{
+ f = f;
+}
More information about the Libstdc++-cvs
mailing list