NULL iterators for <list>

Howard Hinnant hhinnant at
Fri Aug 2 11:24:26 PDT 2013

On Aug 1, 2013, at 1:05 PM, Marshall Clow <mclow.lists at> wrote:

>  says that value-initialized iterators should compare equal.
> Implement that for std::list.
> There are interactions with libc++'s debug mode; hence the extra tests.

Looks pretty good.  Just a couple of comments.


     bool operator==(const __list_iterator& __x, const __list_iterator& __y)
+    if ( __x.__ptr_ == nullptr )
+    	return  __y.__ptr_ == nullptr;

This is unnecessary, and hurts performance.  The existing:

        return __x.__ptr_ == __y.__ptr_;

is all we need.


In both tests you have some iterators default constructed:

+    C::iterator i;

This isn't sufficient to get the desired behavior, unless you take advantage of knowledge of the current implementation.  For example this test would sometimes fail if the implementation changed from:

+    __list_iterator() _NOEXCEPT : __ptr_(nullptr)


+    __list_iterator() = default;

In order to leave open the possibility of changing the implementation without having to re-implement the tests, the tests should always do one of:

    C::iterator i{};
    C::iterator i = C::iterator{};
    C::iterator i = C::iterator();



More information about the cfe-commits mailing list