@@ -828,6 +828,10 @@ private:
828828 template <class _Up >
829829 constexpr static bool __libcpp_opt_ref_ctor_deleted =
830830 is_lvalue_reference_v<_Tp> && reference_constructs_from_temporary_v<_Tp, _Up>;
831+
832+ template <class _Up >
833+ constexpr static bool __ref_ctor_enabled =
834+ is_lvalue_reference_v<_Tp> && !reference_constructs_from_temporary_v<_Tp, _Up>;
831835# endif
832836
833837 // LWG2756: conditionally explicit conversion from _Up
@@ -935,15 +939,15 @@ public:
935939 template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up const &>::template __enable_implicit<_Up>(), int > = 0 >
936940 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional (const optional<_Up>& __v)
937941# if _LIBCPP_STD_VER >= 26
938- noexcept (is_lvalue_reference_v<_Tp> && is_nothrow_constructible_v<_Tp&, _Up&>)
942+ noexcept (is_lvalue_reference_v<_Tp> && is_nothrow_constructible_v<_Tp&, const _Up&>)
939943# endif
940944 {
941945 this ->__construct_from (__v);
942946 }
943947 template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up const &>::template __enable_explicit<_Up>(), int > = 0 >
944948 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional (const optional<_Up>& __v)
945949# if _LIBCPP_STD_VER >= 26
946- noexcept (is_lvalue_reference_v<_Tp> && is_nothrow_constructible_v<_Tp&, _Up&>)
950+ noexcept (is_lvalue_reference_v<_Tp> && is_nothrow_constructible_v<_Tp&, const _Up&>)
947951# endif
948952 {
949953 this ->__construct_from (__v);
@@ -981,25 +985,25 @@ public:
981985
982986 // optional(optional<U>& rhs)
983987 template <class _Up >
984- requires (!__libcpp_opt_ref_ctor_deleted <_Up>) && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
985- (!is_same_v<_Tp&, _Up>) && is_constructible_v<_Tp&, _Up&>
988+ requires __ref_ctor_enabled <_Up&> && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) && (!is_same_v<_Tp&, _Up >) &&
989+ is_constructible_v<_Tp&, _Up&>
986990 _LIBCPP_HIDE_FROM_ABI constexpr explicit (!is_convertible_v<_Up&, _Tp&>)
987991 optional(optional<_Up>& __rhs) noexcept (is_nothrow_constructible_v<_Tp&, _Up&>) {
988992 this ->__construct_from (__rhs);
989993 }
990994
991995 template <class _Up >
992- requires __libcpp_opt_ref_ctor_deleted<_Up> && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
996+ requires __libcpp_opt_ref_ctor_deleted<_Up& > && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
993997 (!is_same_v<_Tp&, _Up>) && is_constructible_v<_Tp&, _Up&>
994998 constexpr explicit optional (optional<_Up>& __rhs) noexcept = delete;
995999
9961000 // optional(const optional<U>&)
9971001 template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up const &>::template __enable_implicit<_Up>(), int > = 0 >
998- requires __libcpp_opt_ref_ctor_deleted<_Up>
1002+ requires __libcpp_opt_ref_ctor_deleted<const _Up& >
9991003 optional (const optional<_Up>&) = delete;
10001004
10011005 template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up const &>::template __enable_explicit<_Up>(), int > = 0 >
1002- requires __libcpp_opt_ref_ctor_deleted<_Up>
1006+ requires __libcpp_opt_ref_ctor_deleted<const _Up& >
10031007 explicit optional (const optional<_Up>&) = delete;
10041008
10051009 // optional(optional<U>&&)
@@ -1013,16 +1017,16 @@ public:
10131017
10141018 // optional(const optional<U>&&)
10151019 template <class _Up >
1016- requires (!__libcpp_opt_ref_ctor_deleted< _Up>) && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
1017- (!is_same_v<_Tp&, _Up>) && is_constructible_v<_Tp&, _Up>
1020+ requires __ref_ctor_enabled< const _Up> && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
1021+ (!is_same_v<_Tp&, _Up>) && is_constructible_v<_Tp&, const _Up>
10181022 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit (!is_convertible_v<const _Up, _Tp&>)
10191023 optional(const optional<_Up>&& __v) noexcept (is_nothrow_constructible_v<_Tp&, const _Up>) {
10201024 this ->__construct_from (std::move (__v));
10211025 }
10221026
10231027 template <class _Up >
1024- requires __libcpp_opt_ref_ctor_deleted<_Up> && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
1025- (!is_same_v<_Tp&, _Up>) && is_constructible_v<_Tp&, _Up>
1028+ requires __libcpp_opt_ref_ctor_deleted<const _Up> && (!is_same_v<remove_cvref_t <_Tp>, optional<_Up>>) &&
1029+ (!is_same_v<_Tp&, _Up>) && is_constructible_v<_Tp&, const _Up>
10261030 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional (const optional<_Up>&& __v) noexcept = delete;
10271031# endif
10281032
0 commit comments