@@ -240,6 +240,7 @@ namespace std {
240
240
# include < __type_traits/is_trivially_relocatable.h>
241
241
# include < __type_traits/is_unbounded_array.h>
242
242
# include < __type_traits/negation.h>
243
+ # include < __type_traits/reference_constructs_from_temporary.h>
243
244
# include < __type_traits/remove_const.h>
244
245
# include < __type_traits/remove_cv.h>
245
246
# include < __type_traits/remove_cvref.h>
@@ -265,6 +266,11 @@ namespace std {
265
266
_LIBCPP_PUSH_MACROS
266
267
# include < __undef_macros>
267
268
269
+ # if _LIBCPP_STD_VER >= 26
270
+ # define _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_TP, _UP ) \
271
+ requires (is_lvalue_reference_v<_TP> && reference_constructs_from_temporary_v<_TP, _UP>)
272
+ # endif
273
+
268
274
namespace std // purposefully not using versioning namespace
269
275
{
270
276
@@ -813,6 +819,41 @@ public:
813
819
this ->__construct_from (std::move (__v));
814
820
}
815
821
822
+ // deleted optional<T&> constructors
823
+ # if _LIBCPP_STD_VER >= 26
824
+ template <class _Up ,
825
+ class ... _Args,
826
+ enable_if_t <is_constructible_v<value_type, initializer_list<_Up>&, _Args...>, int > = 0 >
827
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
828
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t , initializer_list<_Up> __il, _Args&&... __args) = delete;
829
+
830
+ template <class _Up = value_type,
831
+ enable_if_t <_CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>(), int > = 0 >
832
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
833
+ _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) = delete;
834
+
835
+ template <class _Up = remove_cv_t <_Tp>,
836
+ enable_if_t <_CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>(), int > = 0 >
837
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
838
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) = delete;
839
+
840
+ template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up const &>::template __enable_implicit<_Up>(), int > = 0 >
841
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
842
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(const optional<_Up>& __v) = delete;
843
+
844
+ template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up const &>::template __enable_explicit<_Up>(), int > = 0 >
845
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
846
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(const optional<_Up>& __v) = delete;
847
+
848
+ template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_implicit<_Up>(), int > = 0 >
849
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
850
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(optional<_Up>&& __v) = delete;
851
+
852
+ template <class _Up , enable_if_t <_CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_explicit<_Up>(), int > = 0 >
853
+ _LIBCPP_OPT_REF_DELETED_CONS_REQUIRES (_Tp, _Up)
854
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(optional<_Up>&& __v) = delete;
855
+ # endif
856
+
816
857
# if _LIBCPP_STD_VER >= 23
817
858
template <class _Tag ,
818
859
class _Fp ,
@@ -868,7 +909,12 @@ public:
868
909
869
910
template <class _Up ,
870
911
class ... _Args,
871
- enable_if_t <is_constructible_v<value_type, initializer_list<_Up>&, _Args...>, int > = 0 >
912
+ enable_if_t <is_constructible_v<value_type, initializer_list<_Up>&, _Args...>
913
+ # if _LIBCPP_STD_VER >= 26
914
+ && !reference_constructs_from_temporary_v<_Tp&, _Up>
915
+ # endif
916
+ ,
917
+ int > = 0 >
872
918
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace (initializer_list<_Up> __il, _Args&&... __args) {
873
919
reset ();
874
920
this ->__construct (__il, std::forward<_Args>(__args)...);
0 commit comments