[libcxx-commits] [PATCH] D130197: [libc++] Fix `_IterOps::__iter_move` to support proxy iterators.

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 20 14:04:21 PDT 2022


huixie90 added inline comments.


================
Comment at: libcxx/include/__algorithm/iterator_operations.h:70-73
+  static typename remove_reference<
+      typename iterator_traits<__uncvref_t<_Iter> >::reference
+  >::type&& __iter_move(_Iter&& __i) {
     return std::move(*std::forward<_Iter>(__i));
----------------
I am not sure if this solves the problem. 

`std::vector<bool>::iterator::operator*` returns a prvalue `Proxy`. Even the return type is now `Proxy&&`, it is still a dangling reference to a local temporary `Proxy` created by `operator*`

I think we might have to return by value without `std::move` if the `reference` type is a prvalue. (similar to c++17 move_iterator https://timsong-cpp.github.io/cppwp/n4659/move.iterators#move.iterator-1)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130197/new/

https://reviews.llvm.org/D130197



More information about the libcxx-commits mailing list