[libcxx] r187740 - Implement NULL iterators for <list> re: N3644

Marshall Clow mclow.lists at gmail.com
Mon Aug 5 14:23:29 PDT 2013


Author: marshall
Date: Mon Aug  5 16:23:28 2013
New Revision: 187740

URL: http://llvm.org/viewvc/llvm-project?rev=187740&view=rev
Log:
Implement NULL iterators for <list> re: N3644

Added:
    libcxx/trunk/test/containers/sequences/list/db_iterators_9.pass.cpp
Modified:
    libcxx/trunk/include/list
    libcxx/trunk/test/containers/sequences/list/iterators.pass.cpp

Modified: libcxx/trunk/include/list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=187740&r1=187739&r2=187740&view=diff
==============================================================================
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Mon Aug  5 16:23:28 2013
@@ -273,7 +273,7 @@ public:
     typedef typename pointer_traits<pointer>::difference_type difference_type;
 
     _LIBCPP_INLINE_VISIBILITY
-    __list_iterator() _NOEXCEPT
+    __list_iterator() _NOEXCEPT : __ptr_(nullptr)
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
         __get_db()->__insert_i(this);
@@ -403,7 +403,7 @@ public:
     typedef typename pointer_traits<pointer>::difference_type difference_type;
 
     _LIBCPP_INLINE_VISIBILITY
-    __list_const_iterator() _NOEXCEPT
+    __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
         __get_db()->__insert_i(this);

Added: libcxx/trunk/test/containers/sequences/list/db_iterators_9.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/db_iterators_9.pass.cpp?rev=187740&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/db_iterators_9.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/list/db_iterators_9.pass.cpp Mon Aug  5 16:23:28 2013
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// Operations on "NULL" iterators
+
+#if _LIBCPP_DEBUG2 >= 1
+
+#define _LIBCPP_ASSERT(x, m) do { if (!x) throw 1; } while(0)
+
+#include <list>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+struct S { int val; };
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+    {
+	unsigned lib_asserts;
+
+    typedef S T;
+    typedef std::list<T> C;
+    C::iterator i{};
+    C::const_iterator ci{};
+    
+    lib_asserts = 0;
+    try { ++i; }  catch (int) { ++lib_asserts; }
+    try { i++; }  catch (int) { ++lib_asserts; }
+    try { ++ci; } catch (int) { ++lib_asserts; }
+    try { ci++; } catch (int) { ++lib_asserts; }
+    assert(lib_asserts == 4);
+
+    lib_asserts = 0;
+    try { --i; }  catch (int) { ++lib_asserts; }
+    try { i--; }  catch (int) { ++lib_asserts; }
+    try { --ci; } catch (int) { ++lib_asserts; }
+    try { ci--; } catch (int) { ++lib_asserts; }
+    assert(lib_asserts == 4);
+
+    lib_asserts = 0;
+    try { *i; }             catch (int) { ++lib_asserts; }
+    try { *ci; }            catch (int) { ++lib_asserts; }
+    try { (void)  i->val; } catch (int) { ++lib_asserts; }
+    try { (void) ci->val; } catch (int) { ++lib_asserts; }
+    assert(lib_asserts == 4);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Modified: libcxx/trunk/test/containers/sequences/list/iterators.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/iterators.pass.cpp?rev=187740&r1=187739&r2=187740&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/iterators.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/iterators.pass.cpp Mon Aug  5 16:23:28 2013
@@ -135,4 +135,22 @@ int main()
         assert(j->first == 3);
     }
 #endif
+#if _LIBCPP_STD_VER > 11
+    {
+        std::list<int> c;
+        std::list<int>::iterator ii1{}, ii2{};
+        std::list<int>::iterator ii4 = ii1;
+        std::list<int>::const_iterator cii{};
+        assert ( ii1 == ii2 );
+        assert ( ii1 == ii4 );
+        assert ( ii1 == cii );
+
+        assert ( !(ii1 != ii2 ));
+        assert ( !(ii1 != cii ));
+
+        assert ( ii1 != c.cbegin());
+        assert ( cii != c.begin());
+    }
+#endif
+
 }





More information about the cfe-commits mailing list