[llvm] r280564 - ADT: Fix up IListTest.privateNode and get it passing

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 2 18:06:08 PDT 2016


Author: dexonsmith
Date: Fri Sep  2 20:06:08 2016
New Revision: 280564

URL: http://llvm.org/viewvc/llvm-project?rev=280564&view=rev
Log:
ADT: Fix up IListTest.privateNode and get it passing

This test was using the wrong type, and so not actually testing much.
ilist_iterator constructors weren't going through ilist_node_access, so
they didn't actually work with private inheritance.

Modified:
    llvm/trunk/include/llvm/ADT/ilist_iterator.h
    llvm/trunk/include/llvm/ADT/ilist_node.h
    llvm/trunk/unittests/ADT/IListTest.cpp

Modified: llvm/trunk/include/llvm/ADT/ilist_iterator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist_iterator.h?rev=280564&r1=280563&r2=280564&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ilist_iterator.h (original)
+++ llvm/trunk/include/llvm/ADT/ilist_iterator.h Fri Sep  2 20:06:08 2016
@@ -73,8 +73,10 @@ public:
   /// Create from an ilist_node.
   explicit ilist_iterator(node_reference N) : NodePtr(&N) {}
 
-  explicit ilist_iterator(pointer NP) : NodePtr(NP) {}
-  explicit ilist_iterator(reference NR) : NodePtr(&NR) {}
+  explicit ilist_iterator(pointer NP)
+      : NodePtr(ilist_node_access::getNodePtr(NP)) {}
+  explicit ilist_iterator(reference NR)
+      : NodePtr(ilist_node_access::getNodePtr(&NR)) {}
   ilist_iterator() : NodePtr(nullptr) {}
 
   // This is templated so that we can allow constructing a const iterator from
@@ -110,7 +112,7 @@ public:
   // Accessors...
   reference operator*() const {
     assert(!NodePtr->isKnownSentinel());
-    return static_cast<NodeTy &>(*getNodePtr());
+    return *ilist_node_access::getValuePtr(NodePtr);
   }
   pointer operator->() const { return &operator*(); }
 

Modified: llvm/trunk/include/llvm/ADT/ilist_node.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist_node.h?rev=280564&r1=280563&r2=280564&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ilist_node.h (original)
+++ llvm/trunk/include/llvm/ADT/ilist_node.h Fri Sep  2 20:06:08 2016
@@ -76,6 +76,12 @@ struct ilist_node_access {
   template <typename T> static const ilist_node<T> *getNodePtr(const T *N) {
     return N;
   }
+  template <typename T> static T *getValuePtr(ilist_node<T> *N) {
+    return static_cast<T *>(N);
+  }
+  template <typename T> static const T *getValuePtr(const ilist_node<T> *N) {
+    return static_cast<const T *>(N);
+  }
 
   template <typename T> static ilist_node<T> *getPrev(ilist_node<T> &N) {
     return N.getPrev();

Modified: llvm/trunk/unittests/ADT/IListTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/IListTest.cpp?rev=280564&r1=280563&r2=280564&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/IListTest.cpp (original)
+++ llvm/trunk/unittests/ADT/IListTest.cpp Fri Sep  2 20:06:08 2016
@@ -230,14 +230,14 @@ struct PrivateNode : private ilist_node<
 TEST(IListTest, privateNode) {
   // Instantiate various APIs to be sure they're callable when ilist_node is
   // inherited privately.
-  ilist<NodeWithCallback> L;
-  NodeWithCallback N(7);
+  ilist<PrivateNode> L;
+  PrivateNode N(7);
   L.insert(L.begin(), &N);
   ++L.begin();
   (void)*L.begin();
   (void)(L.begin() == L.end());
 
-  ilist<NodeWithCallback> L2;
+  ilist<PrivateNode> L2;
   L2.splice(L2.end(), L);
   L2.remove(&N);
 }




More information about the llvm-commits mailing list