Skip to content

Commit

Permalink
ADT: Fix up IListTest.privateNode and get it passing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dexonsmith committed Sep 3, 2016
1 parent 1211eb0 commit 4ee00f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions include/llvm/ADT/ilist_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ class ilist_iterator
/// 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
Expand Down Expand Up @@ -110,7 +112,7 @@ class ilist_iterator
// Accessors...
reference operator*() const {
assert(!NodePtr->isKnownSentinel());
return static_cast<NodeTy &>(*getNodePtr());
return *ilist_node_access::getValuePtr(NodePtr);
}
pointer operator->() const { return &operator*(); }

Expand Down
6 changes: 6 additions & 0 deletions include/llvm/ADT/ilist_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions unittests/ADT/IListTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4ee00f7

Please sign in to comment.