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.
Details
- Reviewers
ldionne - Group Reviewers
Restricted Project - Commits
- rGbc4d2e705184: [libc++] Fix `_IterOps::__iter_move` to support proxy iterators.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM, please ship this if it passes locally under --param std=X for all standards.
libcxx/include/__algorithm/iterator_operations.h | ||
---|---|---|
68–73 | In particular, I think the comment about dangling references is not super useful here since we have a test for that. |
libcxx/include/__algorithm/iterator_operations.h | ||
---|---|---|
70–73 | 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) |
In particular, I think the comment about dangling references is not super useful here since we have a test for that.