OSDN Git Service

ADT: Fix up IListTest.privateNode and get it passing
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 3 Sep 2016 01:06:08 +0000 (01:06 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 3 Sep 2016 01:06:08 +0000 (01:06 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280564 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/ilist_iterator.h
include/llvm/ADT/ilist_node.h
unittests/ADT/IListTest.cpp

index c39bca3..67c9fa7 100644 (file)
@@ -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*(); }
 
index 4c69c71..a5e2f5e 100644 (file)
@@ -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();
index d7cf980..5fe225b 100644 (file)
@@ -230,14 +230,14 @@ struct PrivateNode : private ilist_node<PrivateNode> {
 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);
 }