diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/containers/sequences/vector | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) | |
download | src-61b9a7258a7693d7f3674a5a1daf7b036ff1d382.tar.gz src-61b9a7258a7693d7f3674a5a1daf7b036ff1d382.zip |
Import libc++ 3.7.0 release (r246257).vendor/libc++/libc++-release_370-r246257
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=287518
svn path=/vendor/libc++/libc++-release_370-r246257/; revision=287519; tag=vendor/libc++/libc++-release_370-r246257
Diffstat (limited to 'test/std/containers/sequences/vector')
73 files changed, 5286 insertions, 0 deletions
diff --git a/test/std/containers/sequences/vector/asan.pass.cpp b/test/std/containers/sequences/vector/asan.pass.cpp new file mode 100644 index 000000000000..86c02b295624 --- /dev/null +++ b/test/std/containers/sequences/vector/asan.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// reference operator[](size_type n); + +#include <vector> +#include <cassert> +#include <cstdlib> + +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_ASAN +extern "C" void __asan_set_error_exit_code(int); + +int main() +{ +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + c.reserve(2*c.size()); + T foo = c[c.size()]; // bad, but not caught by ASAN + } +#endif + + __asan_set_error_exit_code(0); + { + typedef int T; + typedef std::vector<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + c.reserve(2*c.size()); + assert(is_contiguous_container_asan_correct(c)); + assert(!__sanitizer_verify_contiguous_container ( c.data(), c.data() + 1, c.data() + c.capacity())); + T foo = c[c.size()]; // should trigger ASAN + assert(false); // if we got here, ASAN didn't trigger + } +} +#else +int main () { return 0; } +#endif diff --git a/test/std/containers/sequences/vector/asan_throw.pass.cpp b/test/std/containers/sequences/vector/asan_throw.pass.cpp new file mode 100644 index 000000000000..c100da1aade7 --- /dev/null +++ b/test/std/containers/sequences/vector/asan_throw.pass.cpp @@ -0,0 +1,232 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// Test asan vector annotations with a class that throws in a CTOR. + +#include <vector> +#include <cassert> + +#include "asan_testing.h" + +class X { +public: + X(const X &x) { Init(x.a); } + X(char arg) { Init(arg); } + X() { Init(42); } + X &operator=(const X &x) { + Init(x.a); + return *this; + } + void Init(char arg) { + if (arg == 42) + throw 0; + if (arg == 66) + arg = 42; + a = arg; + } + char get() const { return a; } + void set(char arg) { a = arg; } + +private: + char a; +}; + +class ThrowOnCopy { +public: + ThrowOnCopy() : should_throw(false) {} + explicit ThrowOnCopy(bool should_throw) : should_throw(should_throw) {} + + ThrowOnCopy(ThrowOnCopy const & other) + : should_throw(other.should_throw) + { + if (should_throw) { + throw 0; + } + } + + bool should_throw; +}; + +void test_push_back() { + std::vector<X> v; + v.reserve(2); + v.push_back(X(2)); + assert(v.size() == 1); + try { + v.push_back(X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_emplace_back() { +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::vector<X> v; + v.reserve(2); + v.push_back(X(2)); + assert(v.size() == 1); + try { + v.emplace_back(42); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +#endif // _LIBCPP_HAS_NO_VARIADICS +} + +void test_insert_range() { + std::vector<X> v; + v.reserve(4); + v.push_back(X(1)); + v.push_back(X(2)); + assert(v.size() == 2); + assert(v.capacity() >= 4); + try { + char a[2] = {21, 42}; + v.insert(v.end(), a, a + 2); + assert(0); + } catch (int e) { + assert(v.size() == 3); + } + assert(v.size() == 3); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_insert() { + std::vector<X> v; + v.reserve(3); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.insert(v.end(), X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 2); + } + assert(v.size() == 2); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_emplace() { +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::vector<X> v; + v.reserve(3); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.emplace(v.end(), 42); + assert(0); + } catch (int e) { + assert(v.size() == 2); + } + assert(v.size() == 2); + assert(is_contiguous_container_asan_correct(v)); +#endif // _LIBCPP_HAS_NO_VARIADICS +} + +void test_insert_range2() { + std::vector<X> v; + v.reserve(4); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + assert(v.capacity() >= 4); + try { + char a[2] = {10, 42}; + v.insert(v.begin(), a, a + 2); + assert(0); + } catch (int e) { + assert(v.size() <= 4); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + +void test_insert_n() { + std::vector<X> v; + v.reserve(10); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.insert(v.begin(), 1, X(66)); + assert(0); + } catch (int e) { + assert(v.size() <= 3); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + + +void test_insert_n2() { + std::vector<ThrowOnCopy> v(10); + v.reserve(100); + assert(v.size() == 10); + v[6].should_throw = true; + try { + v.insert(v.cbegin(), 5, ThrowOnCopy()); + assert(0); + } catch (int e) { + assert(v.size() == 11); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + +void test_resize() { + std::vector<X> v; + v.reserve(3); + v.push_back(X(0)); + try { + v.resize(3); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_resize_param() { + std::vector<X> v; + v.reserve(3); + v.push_back(X(0)); + try { + v.resize(3, X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +int main() { + test_push_back(); + test_emplace_back(); + test_insert_range(); + test_insert(); + test_emplace(); + test_insert_range2(); + test_insert_n(); + test_insert_n2(); + test_resize(); + test_resize_param(); +} diff --git a/test/std/containers/sequences/vector/const_value_type.pass.cpp b/test/std/containers/sequences/vector/const_value_type.pass.cpp new file mode 100644 index 000000000000..e16e439dec4d --- /dev/null +++ b/test/std/containers/sequences/vector/const_value_type.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector<const int> v; // an extension + +#include <vector> +#include <type_traits> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + std::vector<const int> v = {1, 2, 3}; +#endif +} diff --git a/test/std/containers/sequences/vector/contiguous.pass.cpp b/test/std/containers/sequences/vector/contiguous.pass.cpp new file mode 100644 index 000000000000..32f380778335 --- /dev/null +++ b/test/std/containers/sequences/vector/contiguous.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// An vector is a contiguous container + +#include <vector> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" + +template <class C> +void test_contiguous ( const C &c ) +{ + for ( size_t i = 0; i < c.size(); ++i ) + assert ( *(c.begin() + i) == *(std::addressof(*c.begin()) + i)); +} + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + test_contiguous(C()); + test_contiguous(C(3, 5)); + } + + { + typedef double T; + typedef test_allocator<T> A; + typedef std::vector<T, A> C; + test_contiguous(C(A(3))); + test_contiguous(C(7, 9.0, A(5))); + } +#if __cplusplus >= 201103L + { + typedef double T; + typedef min_allocator<T> A; + typedef std::vector<T, A> C; + test_contiguous(C(A{})); + test_contiguous(C(9, 11.0, A{})); + } +#endif +} diff --git a/test/std/containers/sequences/vector/db_back.pass.cpp b/test/std/containers/sequences/vector/db_back.pass.cpp new file mode 100644 index 000000000000..05f3d07712eb --- /dev/null +++ b/test/std/containers/sequences/vector/db_back.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 back() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_cback.pass.cpp b/test/std/containers/sequences/vector/db_cback.pass.cpp new file mode 100644 index 000000000000..5eb1a353e8b0 --- /dev/null +++ b/test/std/containers/sequences/vector/db_cback.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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 back() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_cfront.pass.cpp b/test/std/containers/sequences/vector/db_cfront.pass.cpp new file mode 100644 index 000000000000..5e54da1d444e --- /dev/null +++ b/test/std/containers/sequences/vector/db_cfront.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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 front() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_cindex.pass.cpp b/test/std/containers/sequences/vector/db_cindex.pass.cpp new file mode 100644 index 000000000000..133aa5652824 --- /dev/null +++ b/test/std/containers/sequences/vector/db_cindex.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_front.pass.cpp b/test/std/containers/sequences/vector/db_front.pass.cpp new file mode 100644 index 000000000000..388058fb3159 --- /dev/null +++ b/test/std/containers/sequences/vector/db_front.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 front() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_index.pass.cpp b/test/std/containers/sequences/vector/db_index.pass.cpp new file mode 100644 index 000000000000..1daf076da67c --- /dev/null +++ b/test/std/containers/sequences/vector/db_index.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_2.pass.cpp b/test/std/containers/sequences/vector/db_iterators_2.pass.cpp new file mode 100644 index 000000000000..2d43843067b7 --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_2.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Compare iterators from different containers with <. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c1; + C c2; + bool b = c1.begin() < c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c1; + C c2; + bool b = c1.begin() < c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_3.pass.cpp b/test/std/containers/sequences/vector/db_iterators_3.pass.cpp new file mode 100644 index 000000000000..051d66c33394 --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_3.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Subtract iterators from different containers. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c1; + C c2; + int i = c1.begin() - c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c1; + C c2; + int i = c1.begin() - c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_4.pass.cpp b/test/std/containers/sequences/vector/db_iterators_4.pass.cpp new file mode 100644 index 000000000000..4c2aa628de14 --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_4.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 iterator out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.begin(); + assert(i[0] == 0); + assert(i[1] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + assert(i[0] == 0); + assert(i[1] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_5.pass.cpp b/test/std/containers/sequences/vector/db_iterators_5.pass.cpp new file mode 100644 index 000000000000..1b1090499c27 --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_5.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Add to iterator out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + i += 2; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + i += 2; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_6.pass.cpp b/test/std/containers/sequences/vector/db_iterators_6.pass.cpp new file mode 100644 index 000000000000..424bc939b136 --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_6.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Decrement iterator prior to begin. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_7.pass.cpp b/test/std/containers/sequences/vector/db_iterators_7.pass.cpp new file mode 100644 index 000000000000..72cdb10cbc85 --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/db_iterators_8.pass.cpp b/test/std/containers/sequences/vector/db_iterators_8.pass.cpp new file mode 100644 index 000000000000..7b898533197c --- /dev/null +++ b/test/std/containers/sequences/vector/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/iterators.pass.cpp b/test/std/containers/sequences/vector/iterators.pass.cpp new file mode 100644 index 000000000000..75a08287a863 --- /dev/null +++ b/test/std/containers/sequences/vector/iterators.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include <vector> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +struct A +{ + int first; + int second; +}; + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector<T> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector<T> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::vector<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::vector<T> C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C::iterator i; + C::const_iterator j; + } + { + typedef A T; + typedef std::vector<T, min_allocator<T>> C; + C c = {A{1, 2}}; + C::iterator i = c.begin(); + i->first = 3; + C::const_iterator j = i; + assert(j->first == 3); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::vector<int> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + } +#endif +} diff --git a/test/std/containers/sequences/vector/types.pass.cpp b/test/std/containers/sequences/vector/types.pass.cpp new file mode 100644 index 000000000000..0fbc7e38b1a2 --- /dev/null +++ b/test/std/containers/sequences/vector/types.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// Test nested types and default template args: + +// template <class T, class Allocator = allocator<T> > +// class vector +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef implementation-defined iterator; +// typedef implementation-defined const_iterator; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef std::reverse_iterator<iterator> reverse_iterator; +// typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +// }; + +#include <vector> +#include <iterator> +#include <type_traits> + +#include "test_allocator.h" +#include "../../Copyable.h" +#include "min_allocator.h" + +struct A { std::vector<A> v; }; // incomplete type support + +template <class T, class Allocator> +void +test() +{ + typedef std::vector<T, Allocator> C; + + static_assert((std::is_same<typename C::value_type, T>::value), ""); + static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), ""); + static_assert((std::is_same<typename C::allocator_type, Allocator>::value), ""); + static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), ""); + static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), ""); + static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), ""); + static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), ""); + static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::const_iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator<typename C::iterator> >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator<typename C::const_iterator> >::value), ""); +} + +int main() +{ + test<int, test_allocator<int> >(); + test<int*, std::allocator<int*> >(); + test<Copyable, test_allocator<Copyable> >(); + static_assert((std::is_same<std::vector<char>::allocator_type, + std::allocator<char> >::value), ""); +#if __cplusplus >= 201103L + static_assert((std::is_same<std::vector<int, min_allocator<int>>::value_type, int>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::allocator_type, min_allocator<int> >::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::reference, int&>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), ""); +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp new file mode 100644 index 000000000000..21082c839f56 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/capacity.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> + +// size_type capacity() const; + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v; + assert(v.capacity() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + assert(v.capacity() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp new file mode 100644 index 000000000000..4df5702f2ad2 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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 reserve(size_type n); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v; + v.reserve(10); + assert(v.capacity() >= 10); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, stack_allocator<int, 250> > v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + v.reserve(10); + assert(v.capacity() >= 10); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp new file mode 100644 index 000000000000..c7988d62060a --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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 resize(size_type sz); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "MoveOnly.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<int> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly>> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp new file mode 100644 index 000000000000..de5126b03d10 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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 resize(size_type sz, const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(v == std::vector<int>(50)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + assert((v == std::vector<int, min_allocator<int>>(50))); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } + { + std::vector<int, min_allocator<int>> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 000000000000..49ab9cc71deb --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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 shrink_to_fit(); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, stack_allocator<int, 401> > v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + { + std::vector<int, stack_allocator<int, 400> > v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 200); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp new file mode 100644 index 000000000000..f3d9289c36eb --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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 swap(vector& x); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v1(100); + std::vector<int> v2(200); + assert(is_contiguous_container_asan_correct(v1)); + assert(is_contiguous_container_asan_correct(v2)); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(is_contiguous_container_asan_correct(v1)); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + assert(is_contiguous_container_asan_correct(v2)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v1(100); + std::vector<int, min_allocator<int>> v2(200); + assert(is_contiguous_container_asan_correct(v1)); + assert(is_contiguous_container_asan_correct(v2)); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(is_contiguous_container_asan_correct(v1)); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp b/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp new file mode 100644 index 000000000000..6f02c3b7bc2b --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/assign_copy.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> + +// vector& operator=(const vector& c); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(5)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::vector<int, min_allocator<int> > l2(l, min_allocator<int>()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp b/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp new file mode 100644 index 000000000000..3cb0b3b095f0 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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 assign(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +template <typename Vec> +void test ( Vec &v ) +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + v.assign({3, 4, 5, 6}); + assert(v.size() == 4); + assert(is_contiguous_container_asan_correct(v)); + assert(v[0] == 3); + assert(v[1] == 4); + assert(v[2] == 5); + assert(v[3] == 6); +#endif +} + +int main() +{ + { + typedef std::vector<int> V; + V d1; + V d2; + d2.reserve(10); // no reallocation during assign. + test(d1); + test(d2); + } + +#if __cplusplus >= 201103L + { + typedef std::vector<int, min_allocator<int>> V; + V d1; + V d2; + d2.reserve(10); // no reallocation during assign. + test(d1); + test(d2); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp b/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp new file mode 100644 index 000000000000..8c8b0a04715b --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector& operator=(vector&& c); + +#include <vector> +#include <cassert> +#include "MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp b/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp new file mode 100644 index 000000000000..e1b30bf11304 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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 assign(size_type n, const_reference v); + +#include <vector> +#include <algorithm> +#include <cassert> +#include <iostream> + +#include "min_allocator.h" +#include "asan_testing.h" + +bool is6(int x) { return x == 6; } + +template <typename Vec> +void test ( Vec &v ) +{ + v.assign(5, 6); + assert(v.size() == 5); + assert(is_contiguous_container_asan_correct(v)); + assert(std::all_of(v.begin(), v.end(), is6)); +} + +int main() +{ + { + typedef std::vector<int> V; + V d1; + V d2; + d2.reserve(10); // no reallocation during assign. + test(d1); + test(d2); + } + +#if __cplusplus >= 201103L + { + typedef std::vector<int, min_allocator<int>> V; + V d1; + V d2; + d2.reserve(10); // no reallocation during assign. + test(d1); + test(d2); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp new file mode 100644 index 000000000000..5e87c07ef70a --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(); +// vector(const Alloc&); + +#include <vector> +#include <cassert> + +#include "test_macros.h" +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test0() +{ +#if TEST_STD_VER > 14 + static_assert((noexcept(C{})), "" ); +#elif TEST_STD_VER >= 11 + static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); +#endif + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c)); +#if TEST_STD_VER >= 11 + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c1)); +#endif +} + +template <class C> +void +test1(const typename C::allocator_type& a) +{ +#if TEST_STD_VER > 14 + static_assert((noexcept(C{typename C::allocator_type{}})), "" ); +#elif TEST_STD_VER >= 11 + static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); +#endif + C c(a); + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == a); + assert(is_contiguous_container_asan_correct(c)); +} + +int main() +{ + { + test0<std::vector<int> >(); + test0<std::vector<NotConstructible> >(); + test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3)); + test1<std::vector<NotConstructible, test_allocator<NotConstructible> > > + (test_allocator<NotConstructible>(5)); + } + { + std::vector<int, stack_allocator<int, 10> > v; + assert(v.empty()); + } +#if TEST_STD_VER >= 11 + { + test0<std::vector<int, min_allocator<int>> >(); + test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >(); + test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{}); + test1<std::vector<NotConstructible, min_allocator<NotConstructible> > > + (min_allocator<NotConstructible>{}); + } + { + std::vector<int, min_allocator<int> > v; + assert(v.empty()); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp new file mode 100644 index 000000000000..36e231acce12 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class InputIter> vector(InputIter first, InputIter last); + +#include <vector> +#include <cassert> + +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C, class Iterator> +void +test(Iterator first, Iterator last) +{ + C c(first, last); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an)); + test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); + test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); + test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); + test<std::vector<int> >(a, an); + + test<std::vector<int, stack_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(a, an); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an)); + test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); + test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); + test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); + test<std::vector<int> >(a, an); +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 000000000000..7fa748a90d71 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class InputIter> vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include <vector> +#include <cassert> + +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C, class Iterator, class A> +void +test(Iterator first, Iterator last, const A& a) +{ + C c(first, last, a); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +#if __cplusplus >= 201103L + +template <class T> +struct implicit_conv_allocator : min_allocator<T> +{ + implicit_conv_allocator(void* p) {} + implicit_conv_allocator(const implicit_conv_allocator&) = default; +}; + +#endif + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::allocator<int> alloc; + test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); + test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); + test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); + test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); + test<std::vector<int> >(a, an, alloc); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + min_allocator<int> alloc; + test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(a, an, alloc); + test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp new file mode 100644 index 000000000000..e03389593f16 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// explicit vector(size_type n); + +#include <vector> +#include <cassert> + +#include "DefaultOnly.h" +#include "min_allocator.h" +#include "test_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); + assert(is_contiguous_container_asan_correct(c)); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template <class C> +void +test1(typename C::size_type n) +{ + C c(n); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c)); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} + +template <class C> +void +test(typename C::size_type n) +{ + test1<C> ( n ); + test2<C> ( n ); +} + +int main() +{ + test<std::vector<int> >(50); + test<std::vector<DefaultOnly> >(500); + assert(DefaultOnly::count == 0); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(50); + test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500); + test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23)); + assert(DefaultOnly::count == 0); +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp new file mode 100644 index 000000000000..5b6c49857044 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test(typename C::size_type n, const typename C::value_type& x) +{ + C c(n, x); + assert(c.__invariants()); + assert(c.size() == n); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<std::vector<int> >(50, 3); + test<std::vector<int, stack_allocator<int, 50> > >(50, 5); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(50, 3); +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp new file mode 100644 index 000000000000..c62b84104aba --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test(typename C::size_type n, const typename C::value_type& x, + const typename C::allocator_type& a) +{ + C c(n, x, a); + assert(c.__invariants()); + assert(a == c.get_allocator()); + assert(c.size() == n); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<std::vector<int> >(50, 3, std::allocator<int>()); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(50, 3, min_allocator<int>()); +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp b/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp new file mode 100644 index 000000000000..677963deeb84 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(const vector& v); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test(const C& x) +{ + unsigned s = x.size(); + C c(x); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); + assert(is_contiguous_container_asan_correct(c)); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<int>(a, an)); + } + { + std::vector<int, test_allocator<int> > v(3, 2, test_allocator<int>(5)); + std::vector<int, test_allocator<int> > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::vector<int, other_allocator<int> > v(3, 2, other_allocator<int>(5)); + std::vector<int, other_allocator<int> > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == other_allocator<int>(-2)); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<int, min_allocator<int>>(a, an)); + } + { + std::vector<int, min_allocator<int> > v(3, 2, min_allocator<int>()); + std::vector<int, min_allocator<int> > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp b/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp new file mode 100644 index 000000000000..128328c2a7d2 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(const vector& v, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test(const C& x, const typename C::allocator_type& a) +{ + unsigned s = x.size(); + C c(x, a); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); + assert(is_contiguous_container_asan_correct(c)); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<int>(a, an), std::allocator<int>()); + } + { + std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(3)); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<int, min_allocator<int>>(a, an), min_allocator<int>()); + } + { + std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::vector<int, min_allocator<int> > l2(l, min_allocator<int>()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp b/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp new file mode 100644 index 000000000000..1a4a1898cc6b --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// class vector +// vector(); + +#include <vector> + +struct X +{ + std::vector<X> q; +}; + +int main() +{ +} diff --git a/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp new file mode 100644 index 000000000000..60f7b72c9477 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector() +// noexcept(is_nothrow_default_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "test_macros.h" +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp new file mode 100644 index 000000000000..0e2cae9ee935 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// ~vector() // implied noexcept; + +#include <vector> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp b/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp new file mode 100644 index 000000000000..7eb834ff3877 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/initializer_list.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> + +// vector(initializer_list<value_type> il); + +#include <vector> +#include <cassert> +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp b/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 000000000000..5d7ae884e382 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.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> + +// vector(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <vector> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int, test_allocator<int>> d({3, 4, 5, 6}, test_allocator<int>(3)); + assert(d.get_allocator() == test_allocator<int>(3)); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d({3, 4, 5, 6}, min_allocator<int>()); + assert(d.get_allocator() == min_allocator<int>()); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/sequences/vector/vector.cons/move.pass.cpp b/test/std/containers/sequences/vector/vector.cons/move.pass.cpp new file mode 100644 index 000000000000..fb419d825d2b --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/move.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(vector&& c); + +#include <vector> +#include <cassert> +#include "MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + assert(is_contiguous_container_asan_correct(c1)); + std::vector<int>::const_iterator i = c1.begin(); + std::vector<int> c2 = std::move(c1); + assert(is_contiguous_container_asan_correct(c2)); + std::vector<int>::iterator j = c2.erase(i); + assert(*j == 3); + assert(is_contiguous_container_asan_correct(c2)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + assert(is_contiguous_container_asan_correct(c1)); + std::vector<int, min_allocator<int>>::const_iterator i = c1.begin(); + std::vector<int, min_allocator<int>> c2 = std::move(c1); + assert(is_contiguous_container_asan_correct(c2)); + std::vector<int, min_allocator<int>>::iterator j = c2.erase(i); + assert(*j == 3); + assert(is_contiguous_container_asan_correct(c2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp b/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp new file mode 100644 index 000000000000..aef96917cb32 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(vector&& c, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator<MoveOnly>(4)); + assert(is_contiguous_container_asan_correct(l2)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator<MoveOnly>()); + assert(is_contiguous_container_asan_correct(l2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 000000000000..1c4a4f7c9282 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector& operator=(vector&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp new file mode 100644 index 000000000000..b7bbfaa421c4 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// vector(vector&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + // In C++17, move constructors for allocators are not allowed to throw +#if TEST_STD_VER > 14 + static_assert( std::is_nothrow_move_constructible<C>::value, ""); +#else + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); +#endif + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp b/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 000000000000..592b71462767 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.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> + +// vector& operator=(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/sequences/vector/vector.data/data.pass.cpp b/test/std/containers/sequences/vector/vector.data/data.pass.cpp new file mode 100644 index 000000000000..aed56bc09310 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.data/data.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> + +// pointer data(); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp b/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp new file mode 100644 index 000000000000..cb6062694e40 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.data/data_const.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> + +// const_pointer data() const; + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + const std::vector<int> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + const std::vector<int> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + const std::vector<int, min_allocator<int>> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + const std::vector<int, min_allocator<int>> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp new file mode 100644 index 000000000000..8af6bdacd0a8 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class... Args> iterator emplace(const_iterator pos, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + A(A&& a) + : i_(a.i_), + d_(a.d_) + { + a.i_ = 0; + a.d_ = 0; + } + + A& operator=(A&& a) + { + i_ = a.i_; + d_ = a.d_; + a.i_ = 0; + a.d_ = 0; + return *this; + } + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<A> c; + std::vector<A>::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } + { + std::vector<A, stack_allocator<A, 7> > c; + std::vector<A, stack_allocator<A, 7> >::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<A> c1; + std::vector<A> c2; + std::vector<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<A, min_allocator<A>> c; + std::vector<A, min_allocator<A>>::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<A, min_allocator<A>> c1; + std::vector<A, min_allocator<A>> c2; + std::vector<A, min_allocator<A>>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp new file mode 100644 index 000000000000..bbf91a4255d7 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + A(A&& a) + : i_(a.i_), + d_(a.d_) + { + a.i_ = 0; + a.d_ = 0; + } + + A& operator=(A&& a) + { + i_ = a.i_; + d_ = a.d_; + a.i_ = 0; + a.d_ = 0; + return *this; + } + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<A> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } + { + std::vector<A, stack_allocator<A, 4> > c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } +#if __cplusplus >= 201103L + { + std::vector<A, min_allocator<A>> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp new file mode 100644 index 000000000000..85a47073bcb2 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class... Args> iterator emplace(const_iterator pos, Args&&... args); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> v; + v.reserve(3); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v; + v.reserve(4); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + v.reserve(3); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v; + v.reserve(4); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp new file mode 100644 index 000000000000..4fa07b729a75 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator erase(const_iterator position); + +#include <vector> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::const_iterator i = l1.begin(); + assert(is_contiguous_container_asan_correct(l1)); + ++i; + std::vector<int>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(is_contiguous_container_asan_correct(l1)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>>::const_iterator i = l1.begin(); + assert(is_contiguous_container_asan_correct(l1)); + ++i; + std::vector<int, min_allocator<int>>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(is_contiguous_container_asan_correct(l1)); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 000000000000..0478d24c79f6 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <cstdlib> +#include <exception> + +#include "min_allocator.h" + +int main() +{ + { + 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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 000000000000..c394f197402b --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <cstdlib> +#include <exception> + +#include "min_allocator.h" + +int main() +{ + { + 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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 000000000000..2e81d133cde0 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,128 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator erase(const_iterator first, const_iterator last); + +#include <vector> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + int a1[] = {1, 2, 3}; + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::vector<int>(a1+1, a1+3)); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::vector<int>(a1+2, a1+3)); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<std::vector<int> > outer(2, std::vector<int>(1)); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + outer.erase(outer.begin(), outer.begin()); + assert(outer.size() == 2); + assert(outer[0].size() == 1); + assert(outer[1].size() == 1); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert((l1 == std::vector<int, min_allocator<int>>(a1+1, a1+3))); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert((l1 == std::vector<int, min_allocator<int>>(a1+2, a1+3))); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<std::vector<int, min_allocator<int>>, min_allocator<std::vector<int, min_allocator<int>>>> outer(2, std::vector<int, min_allocator<int>>(1)); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + outer.erase(outer.begin(), outer.begin()); + assert(outer.size() == 2); + assert(outer[0].size() == 1); + assert(outer[1].size() == 1); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 000000000000..af6d0f757892 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + 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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 000000000000..eee2c66c5c8c --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + 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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 000000000000..505067d05a1a --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + 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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 000000000000..c7e4131cb49c --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + 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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin()); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 000000000000..30b801788013 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> d(10, 1); + std::vector<int>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(is_contiguous_container_asan_correct(d)); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d(10, 1); + std::vector<int, min_allocator<int>>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(is_contiguous_container_asan_correct(d)); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 000000000000..782437be87f8 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "test_iterators.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + int a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == sz + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + v.reserve(128); // force no reallocation + size_t sz = v.size(); + int a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == sz + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 308> > v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> v(100); + std::vector<int> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int, min_allocator<int>> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(false); + } +#endif +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 000000000000..e12ec45febfc --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator insert(const_iterator position, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "MoveOnly.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly> v(100); + std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100); + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> v1(3); + std::vector<int> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly>> v(100); + std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> v1(3); + std::vector<int, min_allocator<int>> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 000000000000..6997284f258c --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + v.reserve(128); // force no reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> c1(100); + std::vector<int> c2; + std::vector<int>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> c1(100); + std::vector<int, min_allocator<int>> c2; + std::vector<int, min_allocator<int>>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); + assert(false); + } +#endif +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 000000000000..782e752157a7 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// iterator insert(const_iterator position, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + while(v.size() < v.capacity()) v.push_back(0); + v.pop_back(); v.pop_back(); // force no reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> v1(3); + std::vector<int> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> v1(3); + std::vector<int, min_allocator<int>> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp new file mode 100644 index 000000000000..62fa60103baa --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +#if _LIBCPP_DEBUG >= 1 +#include <cstdlib> +#include <exception> + +#endif + +int main() +{ + { + std::vector<int> c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp new file mode 100644 index 000000000000..eeeba6242d93 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// 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 push_back(const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } + { + std::vector<int, stack_allocator<int, 15> > c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 000000000000..6615a25a620f --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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 push_back(const value_type& x); + +#include <vector> +#include <cassert> + +#include "asan_testing.h" + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::vector<CMyClass> vec; + + vec.push_back(instance); + std::vector<CMyClass> vec2(vec); + assert(is_contiguous_container_asan_correct(vec)); + assert(is_contiguous_container_asan_correct(vec2)); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + assert(vec==vec2); + assert(is_contiguous_container_asan_correct(vec)); + } +} diff --git a/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 000000000000..b143cd773b42 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// 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 push_back(value_type&& x); + +#include <vector> +#include <cassert> +#include "MoveOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly> c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 15> > c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly>> c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp b/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp new file mode 100644 index 000000000000..e7f6a0011e1a --- /dev/null +++ b/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class T, class Alloc> +// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::vector<int>::iterator i1 = c1.begin(); + std::vector<int>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + c1.erase(i1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::vector<int, min_allocator<int>>::iterator i1 = c1.begin(); + std::vector<int, min_allocator<int>>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + c1.erase(i1); + assert(false); + } +#endif +#endif +} diff --git a/test/std/containers/sequences/vector/vector.special/swap.pass.cpp b/test/std/containers/sequences/vector/vector.special/swap.pass.cpp new file mode 100644 index 000000000000..96aaf7131f53 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.special/swap.pass.cpp @@ -0,0 +1,188 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class T, class Alloc> +// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y); + +#include <vector> +#include <iterator> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1 == std::vector<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2 == std::vector<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1); + std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1 == std::vector<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2 == std::vector<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1); + std::vector<int> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator<int> A; + std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } +#endif + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator<int> A; + std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert((c2 == std::vector<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1); + std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int, min_allocator<int>> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert((c2 == std::vector<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1); + std::vector<int, min_allocator<int>> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator<int> A; + std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#endif +#endif +} diff --git a/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp new file mode 100644 index 000000000000..1d00ff387480 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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 swap(vector& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); +// +// In C++17, the standard says that swap shall have: +// noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value || +// allocator_traits<Allocator>::is_always_equal::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::true_type is_always_equal; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + C c1, c2; +#if TEST_STD_VER >= 14 + // In c++14, if POCS is set, swapping the allocator is required not to throw + static_assert( noexcept(swap(c1, c2)), ""); +#else + static_assert(!noexcept(swap(c1, c2)), ""); +#endif + } +#if TEST_STD_VER >= 14 + { + typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C; + C c1, c2; + // if the allocators are always equal, then the swap can be noexcept + static_assert( noexcept(swap(c1, c2)), ""); + } +#endif + +#endif +} diff --git a/test/std/containers/sequences/vector/version.pass.cpp b/test/std/containers/sequences/vector/version.pass.cpp new file mode 100644 index 000000000000..2c4fa1263de3 --- /dev/null +++ b/test/std/containers/sequences/vector/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +#include <vector> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |