diff --git a/libcxx/include/__algorithm/move.h b/libcxx/include/__algorithm/move.h --- a/libcxx/include/__algorithm/move.h +++ b/libcxx/include/__algorithm/move.h @@ -29,13 +29,13 @@ template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -pair<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) { +__libcpp_pair<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) { while (__first != __last) { *__result = _IterOps<_AlgPolicy>::__iter_move(__first); ++__first; ++__result; } - return std::make_pair(std::move(__first), std::move(__result)); + return std::__make_libcpp_pair(std::move(__first), std::move(__result)); } template ::type, _OutType>::value && is_trivially_move_assignable<_OutType>::value> > inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 -pair<_InType*, _OutType*> __move_impl(_InType* __first, _InType* __last, _OutType* __result) { +__libcpp_pair<_InType*, _OutType*> __move_impl(_InType* __first, _InType* __last, _OutType* __result) { if (__libcpp_is_constant_evaluated() // TODO: Remove this once GCC supports __builtin_memmove during constant evaluation #ifndef _LIBCPP_COMPILER_GCC @@ -54,7 +54,7 @@ return std::__move_impl<_AlgPolicy, _InType*, _InType*, _OutType*>(__first, __last, __result); const size_t __n = static_cast(__last - __first); ::__builtin_memmove(__result, __first, __n * sizeof(_OutType)); - return std::make_pair(__first + __n, __result + __n); + return std::__make_libcpp_pair(__first + __n, __result + __n); } template @@ -76,7 +76,7 @@ && __is_cpp17_contiguous_iterator<_OutIter>::value && is_trivially_move_assignable<__iter_value_type<_OutIter> >::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 -pair, reverse_iterator<_OutIter> > +__libcpp_pair, reverse_iterator<_OutIter> > __move_impl(reverse_iterator<_InIter> __first, reverse_iterator<_InIter> __last, reverse_iterator<_OutIter> __result) { @@ -85,25 +85,27 @@ auto __result_base = std::__unwrap_iter(__result.base()); auto __result_first = __result_base - (__first_base - __last_base); std::__move_impl<_AlgPolicy>(__last_base, __first_base, __result_first); - return std::make_pair(__last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first))); + return std::__make_libcpp_pair( + __last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first))); } template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __enable_if_t::value && is_copy_constructible<_Sent>::value - && is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> > + && is_copy_constructible<_OutIter>::value, __libcpp_pair<_InIter, _OutIter> > __move(_InIter __first, _Sent __last, _OutIter __result) { auto __ret = std::__move_impl<_AlgPolicy>( std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__result)); - return std::make_pair(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second)); + return std::__make_libcpp_pair( + std::__rewrap_iter(__first, __ret.__first_), std::__rewrap_iter(__result, __ret.__second_)); } template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __enable_if_t::value || !is_copy_constructible<_Sent>::value - || !is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> > + || !is_copy_constructible<_OutIter>::value, __libcpp_pair<_InIter, _OutIter> > __move(_InIter __first, _Sent __last, _OutIter __result) { return std::__move_impl<_AlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); } @@ -111,7 +113,7 @@ template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__move<_ClassicAlgPolicy>(__first, __last, __result).second; + return std::__move<_ClassicAlgPolicy>(__first, __last, __result).__second_; } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__algorithm/ranges_move.h b/libcxx/include/__algorithm/ranges_move.h --- a/libcxx/include/__algorithm/ranges_move.h +++ b/libcxx/include/__algorithm/ranges_move.h @@ -40,7 +40,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr static move_result<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) { auto __ret = std::__move<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; + return {std::move(__ret.__first_), std::move(__ret.__second_)}; } template _Sent, weakly_incrementable _OutIter> diff --git a/libcxx/include/__algorithm/rotate.h b/libcxx/include/__algorithm/rotate.h --- a/libcxx/include/__algorithm/rotate.h +++ b/libcxx/include/__algorithm/rotate.h @@ -34,7 +34,7 @@ value_type __tmp = _Ops::__iter_move(__first); _ForwardIterator __lm1 = std::__move<_AlgPolicy>( - _Ops::next(__first), __last, __first).second; + _Ops::next(__first), __last, __first).__second_; *__lm1 = _VSTD::move(__tmp); return __lm1; } diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h --- a/libcxx/include/__utility/pair.h +++ b/libcxx/include/__utility/pair.h @@ -620,6 +620,22 @@ #endif +template +struct __libcpp_pair { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_pair(_FirstT&& __first, _SecondT&& __second) + : __first_(std::forward<_FirstT>(__first)), __second_(std::forward<_SecondT>(__second)) {} + _FirstType __first_; + _SecondType __second_; +}; + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_pair<__uncvref_t<_FirstType>, __uncvref_t<_SecondType> > +__make_libcpp_pair(_FirstType&& __first, _SecondType&& __second) { + return __libcpp_pair<__uncvref_t<_FirstType>, __uncvref_t<_SecondType> >( + std::forward<_FirstType>(__first), std::forward<_SecondType>(__second)); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___UTILITY_PAIR_H diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -280,7 +280,10 @@ module is_sorted { private header "__algorithm/is_sorted.h" } module is_sorted_until { private header "__algorithm/is_sorted_until.h" } module iter_swap { private header "__algorithm/iter_swap.h" } - module iterator_operations { private header "__algorithm/iterator_operations.h" } + module iterator_operations { + private header "__algorithm/iterator_operations.h" + export * + } module lexicographical_compare { private header "__algorithm/lexicographical_compare.h" } module lower_bound { private header "__algorithm/lower_bound.h" } module make_heap { private header "__algorithm/make_heap.h" } diff --git a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp --- a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp +++ b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include