diff options
author | Konstantin Varlamov <varconst@apple.com> | 2022-07-20 13:17:25 -0700 |
---|---|---|
committer | Konstantin Varlamov <varconst@apple.com> | 2022-07-20 13:19:00 -0700 |
commit | bc4d2e70518476f0a445761d43fee8b9e6670368 (patch) | |
tree | 3a487e0c0c780179d00170eee5414461c3149809 /libcxx/include/__algorithm/iterator_operations.h | |
parent | 2ac7b142b12f66ce91c98177f8d7d942ed4cc94c (diff) | |
download | llvm-bc4d2e70518476f0a445761d43fee8b9e6670368.tar.gz |
[libc++] Fix `_IterOps::__iter_move` to support proxy iterators.
The return type was specified incorrectly for proxy iterators that
define `reference` to be a class that implicitly converts to
`value_type`. `__iter_move` would end up returning an object of type
`reference` which would then implicitly convert to `value_type`; thus,
the function will return a `value_type&&` rvalue reference to the local
temporary.
Differential Revision: https://reviews.llvm.org/D130197
Diffstat (limited to 'libcxx/include/__algorithm/iterator_operations.h')
-rw-r--r-- | libcxx/include/__algorithm/iterator_operations.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libcxx/include/__algorithm/iterator_operations.h b/libcxx/include/__algorithm/iterator_operations.h index 03dd2c41e94a..a3840594b8ae 100644 --- a/libcxx/include/__algorithm/iterator_operations.h +++ b/libcxx/include/__algorithm/iterator_operations.h @@ -66,8 +66,10 @@ struct _IterOps<_ClassicAlgPolicy> { // iter_move template <class _Iter> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 - // Declaring the return type is necessary for the C++03 mode (which doesn't support placeholder return types). - static typename iterator_traits<__uncvref_t<_Iter> >::value_type&& __iter_move(_Iter&& __i) { + // Declaring the return type is necessary for C++03, so we basically mirror what `decltype(auto)` would deduce. + static typename remove_reference< + typename iterator_traits<__uncvref_t<_Iter> >::reference + >::type&& __iter_move(_Iter&& __i) { return std::move(*std::forward<_Iter>(__i)); } |