diff options
Diffstat (limited to 'test/std/containers/sequences')
49 files changed, 379 insertions, 369 deletions
diff --git a/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp index b9775eef0673..5e429adb6fc9 100644 --- a/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp +++ b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.data/data.pass.cpp b/test/std/containers/sequences/array/array.data/data.pass.cpp index 08e4fd39d377..d7aed70c98ad 100644 --- a/test/std/containers/sequences/array/array.data/data.pass.cpp +++ b/test/std/containers/sequences/array/array.data/data.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/test/std/containers/sequences/array/array.data/data_const.pass.cpp index 8eb9762dcb89..58840e940899 100644 --- a/test/std/containers/sequences/array/array.data/data_const.pass.cpp +++ b/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.fill/fill.pass.cpp b/test/std/containers/sequences/array/array.fill/fill.pass.cpp index 675f49500627..5bc42ceb89f3 100644 --- a/test/std/containers/sequences/array/array.fill/fill.pass.cpp +++ b/test/std/containers/sequences/array/array.fill/fill.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.size/size.pass.cpp b/test/std/containers/sequences/array/array.size/size.pass.cpp index fe5a0d5c8db0..a833fdc04715 100644 --- a/test/std/containers/sequences/array/array.size/size.pass.cpp +++ b/test/std/containers/sequences/array/array.size/size.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.special/swap.pass.cpp b/test/std/containers/sequences/array/array.special/swap.pass.cpp index 08e437739ee6..c1b0b235ab34 100644 --- a/test/std/containers/sequences/array/array.special/swap.pass.cpp +++ b/test/std/containers/sequences/array/array.special/swap.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.swap/swap.pass.cpp b/test/std/containers/sequences/array/array.swap/swap.pass.cpp index c7a4cb8df38c..651798e1e790 100644 --- a/test/std/containers/sequences/array/array.swap/swap.pass.cpp +++ b/test/std/containers/sequences/array/array.swap/swap.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.tuple/get.fail.cpp b/test/std/containers/sequences/array/array.tuple/get.fail.cpp index 4f4fbcf93af6..13323dd8e519 100644 --- a/test/std/containers/sequences/array/array.tuple/get.fail.cpp +++ b/test/std/containers/sequences/array/array.tuple/get.fail.cpp @@ -11,15 +11,31 @@ // template <size_t I, class T, size_t N> T& get(array<T, N>& a); +// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify. +#if defined(__clang__) +#pragma clang diagnostic ignored "-Warray-bounds" +#endif + #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { typedef double T; typedef std::array<T, 3> C; C c = {1, 2, 3.5}; - std::get<3>(c) = 5.5; // Can't get element 3! + std::get<3>(c) = 5.5; // expected-note {{requested here}} +#if TEST_STD_VER >= 11 + // expected-error@array:* {{static_assert failed "Index out of bounds in std::get<> (std::array)"}} +#else + // expected-error@array:* {{implicit instantiation of undefined template '__static_assert_test<false>'}} +#endif } } diff --git a/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/test/std/containers/sequences/array/array.tuple/get.pass.cpp index d9e242cd420b..4f210c4f762e 100644 --- a/test/std/containers/sequences/array/array.tuple/get.pass.cpp +++ b/test/std/containers/sequences/array/array.tuple/get.pass.cpp @@ -14,12 +14,19 @@ #include <array> #include <cassert> -#if __cplusplus > 201103L +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + + +#if TEST_STD_VER > 11 struct S { std::array<int, 3> a; int k; constexpr S() : a{1,2,3}, k(std::get<2>(a)) {} - }; +}; constexpr std::array<int, 2> getArr () { return { 3, 4 }; } #endif @@ -35,7 +42,7 @@ int main() assert(c[1] == 5.5); assert(c[2] == 3.5); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; diff --git a/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp index 1cbdfa4ff393..04606bf6cf73 100644 --- a/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp +++ b/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -14,6 +14,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -24,7 +30,7 @@ int main() assert(std::get<1>(c) == 2); assert(std::get<2>(c) == 3.5); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; diff --git a/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp new file mode 100644 index 000000000000..a22c91a4de47 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/get_const_rv.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. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <size_t I, class T, size_t N> const T&& get(const array<T, N>&& a); + +// UNSUPPORTED: c++98, c++03 + +#include <array> +#include <memory> +#include <type_traits> +#include <utility> +#include <cassert> + +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + +int main() +{ + + { + typedef std::unique_ptr<double> T; + typedef std::array<T, 1> C; + const C c = {std::unique_ptr<double>(new double(3.5))}; + static_assert(std::is_same<const T&&, decltype(std::get<0>(std::move(c)))>::value, ""); + static_assert(noexcept(std::get<0>(std::move(c))), ""); + const T&& t = std::get<0>(std::move(c)); + assert(*t == 3.5); + } + +#if TEST_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr const C c = {1, 2, 3.5}; + static_assert(std::get<0>(std::move(c)) == 1, ""); + static_assert(std::get<1>(std::move(c)) == 2, ""); + static_assert(std::get<2>(std::move(c)) == 3.5, ""); + } +#endif +} diff --git a/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp index 8eec3ceff514..72ef49b157f6 100644 --- a/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp +++ b/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp @@ -11,14 +11,20 @@ // template <size_t I, class T, size_t N> T&& get(array<T, N>&& a); +// UNSUPPORTED: c++98, c++03 + #include <array> #include <memory> #include <utility> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { typedef std::unique_ptr<double> T; typedef std::array<T, 1> C; @@ -26,5 +32,4 @@ int main() T t = std::get<0>(std::move(c)); assert(*t == 3.5); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/std/containers/sequences/array/at.pass.cpp b/test/std/containers/sequences/array/at.pass.cpp index b5cf8a5aaa8f..5cb89dfeeb9a 100644 --- a/test/std/containers/sequences/array/at.pass.cpp +++ b/test/std/containers/sequences/array/at.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <array> // reference operator[] (size_type) @@ -17,6 +18,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -27,7 +34,7 @@ int main() assert(r1 == 1); r1 = 5.5; assert(c.front() == 5.5); - + C::reference r2 = c.at(2); assert(r2 == 3.5); r2 = 7.5; @@ -50,7 +57,7 @@ int main() catch (const std::out_of_range &) {} } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; diff --git a/test/std/containers/sequences/array/begin.pass.cpp b/test/std/containers/sequences/array/begin.pass.cpp index 9cba0d6fceb0..b12ffc851b84 100644 --- a/test/std/containers/sequences/array/begin.pass.cpp +++ b/test/std/containers/sequences/array/begin.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -27,6 +31,4 @@ int main() *i = 5.5; assert(c[0] == 5.5); } - { - } } diff --git a/test/std/containers/sequences/array/front_back.pass.cpp b/test/std/containers/sequences/array/front_back.pass.cpp index 45a963b9947d..bccaade986ea 100644 --- a/test/std/containers/sequences/array/front_back.pass.cpp +++ b/test/std/containers/sequences/array/front_back.pass.cpp @@ -17,6 +17,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -45,12 +51,12 @@ int main() assert(r2 == 3.5); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; constexpr C c = {1, 2, 3.5}; - + constexpr T t1 = c.front(); static_assert (t1 == 1, ""); diff --git a/test/std/containers/sequences/array/indexing.pass.cpp b/test/std/containers/sequences/array/indexing.pass.cpp index e4dda0dc5cfd..5ccb0b487b95 100644 --- a/test/std/containers/sequences/array/indexing.pass.cpp +++ b/test/std/containers/sequences/array/indexing.pass.cpp @@ -17,6 +17,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -42,13 +48,13 @@ int main() C::const_reference r2 = c[2]; assert(r2 == 3.5); } - -#if _LIBCPP_STD_VER > 11 + +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; constexpr C c = {1, 2, 3.5}; - + constexpr T t1 = c[0]; static_assert (t1 == 1, ""); diff --git a/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp b/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..9223c1ecddcb --- /dev/null +++ b/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <deque> +// The container's value type must be the same as the allocator's value type + +#include <deque> + +int main() +{ + std::deque<int, std::allocator<long> > d; +} diff --git a/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp index 522f839973db..84f04f9d52da 100644 --- a/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp +++ b/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -58,7 +59,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1, M); } @@ -73,7 +73,7 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp index 9eb514ba92f7..2bf2423fb9af 100644 --- a/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -58,7 +59,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1, M, -10); } @@ -73,7 +73,7 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp index fb00069f33b6..0cf0387211d3 100644 --- a/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp +++ b/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -51,7 +52,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1); } @@ -65,7 +65,7 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<int> >(rng[i], rng[j]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp b/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp index 51a37cc33b7a..6507f58e1194 100644 --- a/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp +++ b/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp @@ -15,6 +15,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "min_allocator.h" @@ -44,7 +45,6 @@ template <class C> void test(C& c1, const C& c2) { - std::size_t c1_osize = c1.size(); c1.assign(c2.begin(), c2.end()); assert(distance(c1.begin(), c1.end()) == c1.size()); assert(c1 == c2); @@ -54,8 +54,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); C c2 = make<C>(M); test(c1, c2); @@ -67,7 +65,6 @@ testI(C& c1, const C& c2) { typedef typename C::const_iterator CI; typedef input_iterator<CI> ICI; - std::size_t c1_osize = c1.size(); c1.assign(ICI(c2.begin()), ICI(c2.end())); assert(distance(c1.begin(), c1.end()) == c1.size()); assert(c1 == c2); @@ -77,8 +74,6 @@ template <class C> void testNI(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); C c2 = make<C>(M); testI(c1, c2); @@ -95,7 +90,7 @@ int main() testN<std::deque<int> >(rng[i], rng[j], rng[k]); testNI<std::deque<int> >(1500, 2000, 1000); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp index 3ab79a095fce..e00e0442d22e 100644 --- a/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "min_allocator.h" @@ -44,7 +45,6 @@ void test(C& c1, int size, int v) { typedef typename C::const_iterator CI; - std::size_t c1_osize = c1.size(); c1.assign(size, v); assert(c1.size() == size); assert(distance(c1.begin(), c1.end()) == c1.size()); @@ -56,8 +56,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1, M, -10); } @@ -72,7 +70,7 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp index 7a0a2512ee2f..713f2159e598 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp @@ -11,13 +11,14 @@ // template <class... Args> iterator emplace(const_iterator p, Args&&... args); +// UNSUPPORTED: c++98, c++03 + #include <deque> #include <cassert> #include "../../../Emplaceable.h" #include "min_allocator.h" -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class C> C @@ -45,7 +46,6 @@ template <class C> void test(int P, C& c1) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5)); @@ -59,8 +59,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -87,11 +85,9 @@ testN(int start, int N) } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -99,7 +95,6 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<Emplaceable> >(rng[i], rng[j]); } -#if __cplusplus >= 201103L { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -107,6 +102,4 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); } -#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp index ecb95d72a21e..fbe3cb69ccdd 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp @@ -17,6 +17,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "MoveOnly.h" #include "../../../stack_allocator.h" @@ -49,7 +50,6 @@ void test(int P, const C& c0, const C& c2) { { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef input_iterator<CI> BCI; C c1 = c0; @@ -67,7 +67,6 @@ test(int P, const C& c0, const C& c2) assert(*i == j); } { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef forward_iterator<CI> BCI; C c1 = c0; @@ -85,7 +84,6 @@ test(int P, const C& c0, const C& c2) assert(*i == j); } { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef bidirectional_iterator<CI> BCI; C c1 = c0; @@ -108,8 +106,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -170,7 +166,6 @@ template <class C> void testI(int P, C& c1, const C& c2) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef input_iterator<CI> ICI; std::size_t c1_osize = c1.size(); @@ -191,8 +186,6 @@ template <class C> void testNI(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -244,7 +237,7 @@ template <class C> void test_move() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if TEST_STD_VER >= 11 C c; typedef typename C::const_iterator CI; { @@ -263,7 +256,7 @@ test_move() j = 0; for (CI i = c.begin(); i != c.end(); ++i, ++j) assert(*i == MoveOnly(j)); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif } int main() @@ -276,11 +269,11 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); testNI<std::deque<int> >(1500, 2000, 1000); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if TEST_STD_VER >= 11 test_move<std::deque<MoveOnly, stack_allocator<MoveOnly, 2000> > >(); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp index b7e73f265028..3c7b0fef28b4 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp @@ -11,13 +11,14 @@ // iterator insert (const_iterator p, value_type&& v); +// UNSUPPORTED: c++98, c++03 + #include <deque> #include <cassert> #include "MoveOnly.h" #include "min_allocator.h" -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class C> C @@ -45,7 +46,6 @@ template <class C> void test(int P, C& c1, int x) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.insert(c1.begin() + P, MoveOnly(x)); @@ -65,8 +65,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -93,11 +91,8 @@ testN(int start, int N) } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -105,7 +100,6 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<MoveOnly> >(rng[i], rng[j]); } -#if __cplusplus >= 201103L { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -113,6 +107,4 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]); } -#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp index 2737dfba7739..0efe3b44c604 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp @@ -16,6 +16,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -44,7 +45,6 @@ template <class C> void test(int P, C& c1, int size, int x) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.insert(c1.begin() + P, size, x); @@ -64,8 +64,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -145,7 +143,7 @@ int main() testN<std::deque<int> >(rng[i], rng[j], rng[k]); self_reference_test<std::deque<int> >(); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp index fbbaad4f89e5..04c4ca4f7b26 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -42,7 +43,6 @@ template <class C> void test(int P, C& c1, int x) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.insert(c1.begin() + P, x); @@ -62,8 +62,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -126,7 +124,7 @@ int main() testN<std::deque<int> >(rng[i], rng[j]); self_reference_test<std::deque<int> >(); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp index 8ad6b53f1b5f..b37e961e442f 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <deque> // void push_back(const value_type& x); diff --git a/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp index e01b2a224ffd..b4caa947aed8 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <deque> // void push_front(const value_type& x); diff --git a/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp b/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..b53075d033bc --- /dev/null +++ b/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <forward_list> +// The container's value type must be the same as the allocator's value type + +#include <forward_list> + +int main() +{ + std::forward_list<int, std::allocator<long> > fl; +} diff --git a/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp index 8341f7ba0cb2..88ecb7540951 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp @@ -24,7 +24,7 @@ int main() #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef MoveOnly T; - typedef test_allocator<int> A; + typedef test_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -39,7 +39,7 @@ int main() } { typedef MoveOnly T; - typedef other_allocator<int> A; + typedef other_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -55,7 +55,7 @@ int main() #if __cplusplus >= 201103L { typedef MoveOnly T; - typedef min_allocator<int> A; + typedef min_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; diff --git a/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp index 6bb575ef80f1..3f0e45af1f0b 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp @@ -24,7 +24,7 @@ int main() #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef MoveOnly T; - typedef test_allocator<int> A; + typedef test_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -39,7 +39,7 @@ int main() } { typedef MoveOnly T; - typedef test_allocator<int> A; + typedef test_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -55,7 +55,7 @@ int main() #if __cplusplus >= 201103L { typedef MoveOnly T; - typedef min_allocator<int> A; + typedef min_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; diff --git a/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp index 43c62eb00cbf..b501347e7893 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <forward_list> // void push_front(const value_type& x); diff --git a/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp index 296ffcd6955d..349a3872d754 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp @@ -15,6 +15,7 @@ #include <cassert> #include <iterator> +#include "test_macros.h" #include "min_allocator.h" typedef int T; @@ -44,7 +45,6 @@ tests(const C& c, int p, int f) { typename C::const_iterator i = c.begin(); int n = 0; - int d = 1; if (p == f || p == f+1) { for (n = 0; n < size_t1; ++n, ++i) @@ -106,7 +106,7 @@ int main() } } } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { // splicing different containers typedef std::forward_list<T, min_allocator<T>> C; diff --git a/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp index ca673b583683..9f01fed66465 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp @@ -22,12 +22,12 @@ #include <algorithm> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> void test(int N, int M) { - typedef typename C::value_type T; C c1; for (int i = 0; i < N; ++i) c1.push_front(i); @@ -52,7 +52,7 @@ int main() for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int> >(i, j); -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int, min_allocator<int>> >(i, j); diff --git a/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp index 42e245d007b0..e65e064ffdaf 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp @@ -30,12 +30,12 @@ #include <algorithm> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> void test(int N, int M) { - typedef typename C::value_type T; C c1; for (int i = 0; i < N; ++i) c1.push_front(i); @@ -57,7 +57,7 @@ int main() for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int> >(i, j); -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int, min_allocator<int>> >(i, j); diff --git a/test/std/containers/sequences/list/allocator_mismatch.fail.cpp b/test/std/containers/sequences/list/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..3490d106a60c --- /dev/null +++ b/test/std/containers/sequences/list/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> +// The container's value type must be the same as the allocator's value type + +#include <list> + +int main() +{ + std::list<int, std::allocator<long> > l; +} diff --git a/test/std/containers/sequences/list/incomplete_type.pass.cpp b/test/std/containers/sequences/list/incomplete_type.pass.cpp new file mode 100644 index 000000000000..adfb4d45fc81 --- /dev/null +++ b/test/std/containers/sequences/list/incomplete_type.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Check that std::list and it's iterators can be instantiated with an incomplete +// type. + +#include <list> + +struct A { + std::list<A> l; + std::list<A>::iterator it; + std::list<A>::const_iterator cit; + std::list<A>::reverse_iterator rit; + std::list<A>::const_reverse_iterator crit; +}; + +int main() { + A a; +} diff --git a/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp b/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp index a7f1917ab856..736b9baae746 100644 --- a/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // template <InputIterator Iter> diff --git a/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp b/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp index eeb74b83e509..c0f6ed198751 100644 --- a/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // iterator insert(const_iterator position, size_type n, const value_type& x); diff --git a/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp b/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp index 406e93a376a1..1aacb63e4a70 100644 --- a/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // iterator insert(const_iterator position, const value_type& x); diff --git a/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp index 9d3c05e26b1c..8d16142defc0 100644 --- a/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // void push_back(const value_type& x); diff --git a/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp index 6609005262eb..aafcceecd471 100644 --- a/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // void push_front(const value_type& x); diff --git a/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp b/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp index b580eb4ae3b0..4dd871c9447e 100644 --- a/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp +++ b/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp @@ -28,6 +28,32 @@ struct some_alloc some_alloc(const some_alloc&); }; +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_move_assignment; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_move_assignment; + typedef std::false_type is_always_equal; +}; + int main() { #if __has_feature(cxx_noexcept) @@ -45,7 +71,22 @@ int main() } { typedef std::vector<bool, some_alloc<bool>> C; +#if TEST_STD_VER > 14 + static_assert( std::is_nothrow_move_assignable<C>::value, ""); +#else static_assert(!std::is_nothrow_move_assignable<C>::value, ""); +#endif + } +#if TEST_STD_VER > 14 + { // POCMA false, is_always_equal true + typedef std::vector<bool, some_alloc2<bool>> C; + static_assert( std::is_nothrow_move_assignable<C>::value, ""); } + { // POCMA false, is_always_equal false + typedef std::vector<bool, some_alloc3<bool>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif + #endif } diff --git a/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp b/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..65fdb63ee6a0 --- /dev/null +++ b/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// The container's value type must be the same as the allocator's value type + +#include <vector> + +int main() +{ + std::vector<int, std::allocator<long> > v; +} diff --git a/test/std/containers/sequences/vector/asan.pass.cpp b/test/std/containers/sequences/vector/asan.pass.cpp deleted file mode 100644 index 86c02b295624..000000000000 --- a/test/std/containers/sequences/vector/asan.pass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 deleted file mode 100644 index c100da1aade7..000000000000 --- a/test/std/containers/sequences/vector/asan_throw.pass.cpp +++ /dev/null @@ -1,232 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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/vector.cons/move_assign_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp index 1c4a4f7c9282..c09224497966 100644 --- 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 @@ -29,6 +29,33 @@ struct some_alloc some_alloc(const some_alloc&); }; +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_move_assignment; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_move_assignment; + typedef std::false_type is_always_equal; +}; + + int main() { #if __has_feature(cxx_noexcept) @@ -46,7 +73,24 @@ int main() } { typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + // In C++17, move assignment for allocators are not allowed to throw +#if TEST_STD_VER > 14 + static_assert( std::is_nothrow_move_assignable<C>::value, ""); +#else + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); +#endif + } + +#if TEST_STD_VER > 14 + { // POCMA false, is_always_equal true + typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C; + static_assert( std::is_nothrow_move_assignable<C>::value, ""); + } + { // POCMA false, is_always_equal false + typedef std::vector<MoveOnly, some_alloc3<MoveOnly>> C; static_assert(!std::is_nothrow_move_assignable<C>::value, ""); } #endif + +#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 index 6615a25a620f..785225357d4b 100644 --- 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 @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <vector> // void push_back(const value_type& x); |