diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2013-08-05 21:23:28 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2013-08-05 21:23:28 +0000 |
commit | 0c37cfd8b87a21def1ae0b0fa9a09acf708ce97c (patch) | |
tree | 0ddc0e2734071bbf54b74f6fc2b6ea6c9fa4fddb /libcxx | |
parent | 6964f33fc91423a0ba3b648c7aad070eb6d610b9 (diff) | |
download | bcm5719-llvm-0c37cfd8b87a21def1ae0b0fa9a09acf708ce97c.tar.gz bcm5719-llvm-0c37cfd8b87a21def1ae0b0fa9a09acf708ce97c.zip |
Implement NULL iterators for <list> re: N3644
llvm-svn: 187740
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/list | 4 | ||||
-rw-r--r-- | libcxx/test/containers/sequences/list/db_iterators_9.pass.cpp | 67 | ||||
-rw-r--r-- | libcxx/test/containers/sequences/list/iterators.pass.cpp | 18 |
3 files changed, 87 insertions, 2 deletions
diff --git a/libcxx/include/list b/libcxx/include/list index 4041b88d6b1..4b1272a8ea4 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -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); diff --git a/libcxx/test/containers/sequences/list/db_iterators_9.pass.cpp b/libcxx/test/containers/sequences/list/db_iterators_9.pass.cpp new file mode 100644 index 00000000000..6f4a5af3633 --- /dev/null +++ b/libcxx/test/containers/sequences/list/db_iterators_9.pass.cpp @@ -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 diff --git a/libcxx/test/containers/sequences/list/iterators.pass.cpp b/libcxx/test/containers/sequences/list/iterators.pass.cpp index 94e4200094a..9f6a51b951f 100644 --- a/libcxx/test/containers/sequences/list/iterators.pass.cpp +++ b/libcxx/test/containers/sequences/list/iterators.pass.cpp @@ -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 + } |