aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-30 21:37:02 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-11-30 21:39:17 +0000
commitc2c7d71eeeab7c6e2a8124b53d6eae6c59781e79 (patch)
tree9474ce057d32bc1d38e51d6e2478aadbc1cb77ec
parent91f4550e1700b7fcc15baa37cbcd517cc02dc975 (diff)
downloadgcc-c2c7d71eeeab7c6e2a8124b53d6eae6c59781e79.zip
gcc-c2c7d71eeeab7c6e2a8124b53d6eae6c59781e79.tar.gz
gcc-c2c7d71eeeab7c6e2a8124b53d6eae6c59781e79.tar.bz2
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.
-rw-r--r--libstdc++-v3/include/std/optional4
-rw-r--r--libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc16
2 files changed, 18 insertions, 2 deletions
diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index b8eedee..55e56cf 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 0000000..9443e16
--- /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;
+}