[PATCH] D157453: Fix "use after move" in iterator_range

Andy Kaylor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 8 16:19:19 PDT 2023

andrew.w.kaylor created this revision.
andrew.w.kaylor added reviewers: steakhal, dblaikie.
Herald added a project: All.
andrew.w.kaylor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

A static analysis tool reported a "use after move" error in a place where the same object was being passed to two different calls using std::forward. While this seems unlikely to present an actual problem, removing the std::forward makes the code slightly more robust.

This is an update to D152891 <https://reviews.llvm.org/D152891>.



Index: llvm/include/llvm/ADT/iterator_range.h
--- llvm/include/llvm/ADT/iterator_range.h
+++ llvm/include/llvm/ADT/iterator_range.h
@@ -53,8 +53,7 @@
                 detail::IterOfRange<Container>, IteratorT>::value> * = nullptr>
   iterator_range(Container &&c)
-      : begin_iterator(adl_begin(std::forward<Container>(c))),
-        end_iterator(adl_end(std::forward<Container>(c))) {
+      : begin_iterator(adl_begin(c)), end_iterator(adl_end(c)) {
   iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
       : begin_iterator(std::move(begin_iterator)),

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157453.548393.patch
Type: text/x-patch
Size: 656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230808/28681700/attachment.bin>

More information about the llvm-commits mailing list