llvm.org GIT mirror llvm / 4ee00f7
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280564 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 3 years ago
3 changed file(s) with 14 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
7272 /// Create from an ilist_node.
7373 explicit ilist_iterator(node_reference N) : NodePtr(&N) {}
7474
75 explicit ilist_iterator(pointer NP) : NodePtr(NP) {}
76 explicit ilist_iterator(reference NR) : NodePtr(&NR) {}
75 explicit ilist_iterator(pointer NP)
76 : NodePtr(ilist_node_access::getNodePtr(NP)) {}
77 explicit ilist_iterator(reference NR)
78 : NodePtr(ilist_node_access::getNodePtr(&NR)) {}
7779 ilist_iterator() : NodePtr(nullptr) {}
7880
7981 // This is templated so that we can allow constructing a const iterator from
109111 // Accessors...
110112 reference operator*() const {
111113 assert(!NodePtr->isKnownSentinel());
112 return static_cast(*getNodePtr());
114 return *ilist_node_access::getValuePtr(NodePtr);
113115 }
114116 pointer operator->() const { return &operator*(); }
115117
7474 template static ilist_node *getNodePtr(T *N) { return N; }
7575 template static const ilist_node *getNodePtr(const T *N) {
7676 return N;
77 }
78 template static T *getValuePtr(ilist_node *N) {
79 return static_cast(N);
80 }
81 template static const T *getValuePtr(const ilist_node *N) {
82 return static_cast(N);
7783 }
7884
7985 template static ilist_node *getPrev(ilist_node &N) {
229229 TEST(IListTest, privateNode) {
230230 // Instantiate various APIs to be sure they're callable when ilist_node is
231231 // inherited privately.
232 ilist L;
233 NodeWithCallback N(7);
232 ilist L;
233 PrivateNode N(7);
234234 L.insert(L.begin(), &N);
235235 ++L.begin();
236236 (void)*L.begin();
237237 (void)(L.begin() == L.end());
238238
239 ilist<NodeWithCallback> L2;
239 ilist<PrivateNode> L2;
240240 L2.splice(L2.end(), L);
241241 L2.remove(&N);
242242 }