Index: llvm/include/llvm/ADT/BreadthFirstIterator.h =================================================================== --- llvm/include/llvm/ADT/BreadthFirstIterator.h +++ llvm/include/llvm/ADT/BreadthFirstIterator.h @@ -50,7 +50,7 @@ using value_type = typename GT::NodeRef; using difference_type = std::ptrdiff_t; using pointer = value_type *; - using reference = value_type &; + using reference = const value_type &; private: using NodeRef = typename GT::NodeRef; @@ -123,7 +123,7 @@ bool operator!=(const bf_iterator &RHS) const { return !(*this == RHS); } - const NodeRef &operator*() const { return VisitQueue.front()->first; } + reference operator*() const { return VisitQueue.front()->first; } // This is a nonstandard operator-> that dereferences the pointer an extra // time so that you can actually call methods on the node, because the Index: llvm/include/llvm/ADT/DepthFirstIterator.h =================================================================== --- llvm/include/llvm/ADT/DepthFirstIterator.h +++ llvm/include/llvm/ADT/DepthFirstIterator.h @@ -88,7 +88,7 @@ using value_type = typename GT::NodeRef; using difference_type = std::ptrdiff_t; using pointer = value_type *; - using reference = value_type &; + using reference = const value_type &; private: using NodeRef = typename GT::NodeRef; @@ -165,7 +165,7 @@ } bool operator!=(const df_iterator &x) const { return !(*this == x); } - const NodeRef &operator*() const { return VisitStack.back().first; } + reference operator*() const { return VisitStack.back().first; } // This is a nonstandard operator-> that dereferences the pointer an extra // time... so that you can actually call methods ON the Node, because Index: llvm/include/llvm/ADT/PostOrderIterator.h =================================================================== --- llvm/include/llvm/ADT/PostOrderIterator.h +++ llvm/include/llvm/ADT/PostOrderIterator.h @@ -100,7 +100,7 @@ using value_type = typename GT::NodeRef; using difference_type = std::ptrdiff_t; using pointer = value_type *; - using reference = value_type &; + using reference = const value_type &; private: using NodeRef = typename GT::NodeRef; @@ -158,7 +158,7 @@ } bool operator!=(const po_iterator &x) const { return !(*this == x); } - const NodeRef &operator*() const { return VisitStack.back().first; } + reference operator*() const { return VisitStack.back().first; } // This is a nonstandard operator-> that dereferences the pointer an extra // time... so that you can actually call methods ON the BasicBlock, because Index: llvm/unittests/ADT/BreadthFirstIteratorTest.cpp =================================================================== --- llvm/unittests/ADT/BreadthFirstIteratorTest.cpp +++ llvm/unittests/ADT/BreadthFirstIteratorTest.cpp @@ -70,4 +70,8 @@ EXPECT_EQ(It, End); } +static_assert( + std::is_convertible_v>>()), + typename bf_iterator>::reference>); + } // end namespace llvm Index: llvm/unittests/ADT/DepthFirstIteratorTest.cpp =================================================================== --- llvm/unittests/ADT/DepthFirstIteratorTest.cpp +++ llvm/unittests/ADT/DepthFirstIteratorTest.cpp @@ -50,4 +50,9 @@ EXPECT_EQ(3, S.InsertVisited); } + +static_assert( + std::is_convertible_v>>()), + typename df_iterator>::reference>); + } Index: llvm/unittests/ADT/PostOrderIteratorTest.cpp =================================================================== --- llvm/unittests/ADT/PostOrderIteratorTest.cpp +++ llvm/unittests/ADT/PostOrderIteratorTest.cpp @@ -36,6 +36,10 @@ PIExt.insertEdge(std::optional(), NullBB); } +static_assert( + std::is_convertible_v>>()), + typename po_iterator>::reference>); + // Test post-order and reverse post-order traversals for simple graph type. TEST(PostOrderIteratorTest, PostOrderAndReversePostOrderTraverrsal) { Graph<6> G;