diff --git a/include/llvm/ADT/ilist_node.h b/include/llvm/ADT/ilist_node.h index 3de4f156d20..f0080035cb8 100644 --- a/include/llvm/ADT/ilist_node.h +++ b/include/llvm/ADT/ilist_node.h @@ -67,7 +67,7 @@ public: /// \brief Get the previous node, or 0 for the list head. const NodeTy *getPrevNode() const { - NodeTy *Prev = this->getPrev(); + const NodeTy *Prev = this->getPrev(); // Check for sentinel. if (!Prev->getNext()) @@ -89,7 +89,7 @@ public: /// \brief Get the next node, or 0 for the list tail. const NodeTy *getNextNode() const { - NodeTy *Next = getNext(); + const NodeTy *Next = getNext(); // Check for sentinel. if (!Next->getNext()) diff --git a/unittests/ADT/ilistTest.cpp b/unittests/ADT/ilistTest.cpp index 3bf04dccc2c..09a699a9624 100644 --- a/unittests/ADT/ilistTest.cpp +++ b/unittests/ADT/ilistTest.cpp @@ -34,6 +34,11 @@ TEST(ilistTest, Basic) { EXPECT_EQ(2, List.back().Value); EXPECT_EQ(2, List.front().getNextNode()->Value); EXPECT_EQ(1, List.back().getPrevNode()->Value); + + const ilist &ConstList = List; + EXPECT_EQ(2, ConstList.back().Value); + EXPECT_EQ(2, ConstList.front().getNextNode()->Value); + EXPECT_EQ(1, ConstList.back().getPrevNode()->Value); } }