diff options
author | Howard Hinnant <hhinnant@apple.com> | 2013-03-25 22:12:26 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2013-03-25 22:12:26 +0000 |
commit | ea1bbbd1359fbacd5bd874baf590a5c1f08429b5 (patch) | |
tree | 37b3b7668b1d7d9aa23d477c0140ea2b05ee2df8 | |
parent | a2372390970d660c277a0c41c3d15a83e8de24cf (diff) | |
download | bcm5719-llvm-ea1bbbd1359fbacd5bd874baf590a5c1f08429b5.tar.gz bcm5719-llvm-ea1bbbd1359fbacd5bd874baf590a5c1f08429b5.zip |
Added debug tests for indexing, pop_back and both forms of erase. Added an improved error message for erasing a single element with end().
llvm-svn: 177929
10 files changed, 407 insertions, 0 deletions
diff --git a/libcxx/include/vector b/libcxx/include/vector index d9c5c2f4f0d..11d9a1b6d33 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -1550,6 +1550,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __position) "vector::erase(iterator) called with an iterator not" " referring to this vector"); #endif + _LIBCPP_ASSERT(__position != end(), + "vector::erase(iterator) called with a non-dereferenceable iterator"); pointer __p = const_cast<pointer>(&*__position); iterator __r = __make_iter(__p); this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); diff --git a/libcxx/test/containers/sequences/vector/db_cindex.pass.cpp b/libcxx/test/containers/sequences/vector/db_cindex.pass.cpp new file mode 100644 index 00000000000..5fef131ed1c --- /dev/null +++ b/libcxx/test/containers/sequences/vector/db_cindex.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Index const vector out of bounds. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + typedef int T; + typedef std::vector<T> C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/db_index.pass.cpp b/libcxx/test/containers/sequences/vector/db_index.pass.cpp new file mode 100644 index 00000000000..e906decc796 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/db_index.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Index vector out of bounds. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..29669342521 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <cstdlib> +#include <exception> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..f67ddb4aa1c --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <cstdlib> +#include <exception> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..11395baa627 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..202fef4aeef --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..6df60bdbbf2 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..a8bc2be64b5 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_terminate(f1); + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin()); + assert(false); +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..ac6ee04bc29 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void pop_back(); + +#if _LIBCPP_DEBUG2 >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate()) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +#if _LIBCPP_DEBUG2 >= 1 +#include <cstdlib> +#include <exception> + +void f1() +{ + std::exit(0); +} +#endif + +int main() +{ +#if _LIBCPP_DEBUG2 >= 1 + std::set_terminate(f1); +#endif + { + std::vector<int> c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG2 >= 1 + c.pop_back(); + assert(false); +#endif + } +} |