[llvm] 33af74d - Fix "use after move" in iterator_range

Andy Kaylor via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 14 11:04:31 PDT 2023


Author: Andy Kaylor
Date: 2023-08-14T11:04:12-07:00
New Revision: 33af74d6a02dc8d2980a2abb3ed94dafbeb46c30

URL: https://github.com/llvm/llvm-project/commit/33af74d6a02dc8d2980a2abb3ed94dafbeb46c30
DIFF: https://github.com/llvm/llvm-project/commit/33af74d6a02dc8d2980a2abb3ed94dafbeb46c30.diff

LOG: Fix "use after move" in iterator_range

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 relates to the comments here: https://reviews.llvm.org/D152891#inline-1522454

Differential Revision: https://reviews.llvm.org/D157453

Added: 
    

Modified: 
    llvm/include/llvm/ADT/iterator_range.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/iterator_range.h b/llvm/include/llvm/ADT/iterator_range.h
index 8c37455dc219fc..2dc227935984b1 100644
--- a/llvm/include/llvm/ADT/iterator_range.h
+++ b/llvm/include/llvm/ADT/iterator_range.h
@@ -53,8 +53,7 @@ class iterator_range {
                 detail::IterOfRange<Container>, IteratorT>::value> * = nullptr>
 #endif
   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)),


        


More information about the llvm-commits mailing list