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.
This commit is contained in:
Jonathan Wakely 2024-11-30 21:37:02 +00:00 committed by Jonathan Wakely
parent 91f4550e17
commit c2c7d71eee
No known key found for this signature in database
2 changed files with 18 additions and 2 deletions

View file

@ -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)

View file

@ -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;
}