diff options
Diffstat (limited to 'test/std/utilities/utility')
17 files changed, 274 insertions, 92 deletions
diff --git a/test/std/utilities/utility/as_const/as_const.pass.cpp b/test/std/utilities/utility/as_const/as_const.pass.cpp index ff3f84a5532f..7bb5849d0bd0 100644 --- a/test/std/utilities/utility/as_const/as_const.pass.cpp +++ b/test/std/utilities/utility/as_const/as_const.pass.cpp @@ -27,7 +27,7 @@ void test(T& t) static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const<const T>(t))>::type>::value, ""); static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const<volatile T>(t))>::type>::value, ""); static_assert(std::is_const<typename std::remove_reference<decltype(std::as_const<const volatile T>(t))>::type>::value, ""); - + assert(std::as_const(t) == t); assert(std::as_const< T>(t) == t); assert(std::as_const<const T>(t) == t); diff --git a/test/std/utilities/utility/exchange/exchange.pass.cpp b/test/std/utilities/utility/exchange/exchange.pass.cpp index 620b4149d1d0..5ef0ac3b09f5 100644 --- a/test/std/utilities/utility/exchange/exchange.pass.cpp +++ b/test/std/utilities/utility/exchange/exchange.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 // utilities // exchange @@ -17,7 +18,6 @@ int main() { -#if _LIBCPP_STD_VER > 11 { int v = 12; assert ( std::exchange ( v, 23 ) == 12 ); @@ -27,7 +27,7 @@ int main() assert ((std::exchange<int, float> ( v, {} )) == 67 ); assert ( v == 0 ); - + } { @@ -48,11 +48,9 @@ int main() s3 = s2; // Dad assert ( std::exchange ( s3, {} ) == s2 ); assert ( s3.size () == 0 ); - + s3 = s2; // Dad assert ( std::exchange ( s3, "" ) == s2 ); assert ( s3.size () == 0 ); } - -#endif } diff --git a/test/std/utilities/utility/forward/forward.pass.cpp b/test/std/utilities/utility/forward/forward.pass.cpp index 357b36fafa96..94575485df04 100644 --- a/test/std/utilities/utility/forward/forward.pass.cpp +++ b/test/std/utilities/utility/forward/forward.pass.cpp @@ -39,6 +39,9 @@ int main() A a; const A ca = A(); + ((void)a); // Prevent unused warning + ((void)ca); // Prevent unused warning + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp index fcda3664d9b6..9ef7bcff2ba8 100644 --- a/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp +++ b/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp @@ -18,6 +18,8 @@ #include <utility> #include <cassert> +#include "test_macros.h" + int main() { { @@ -27,7 +29,7 @@ int main() assert(std::get<1>(p) == 4); } -#if __cplusplus > 201103L +#if TEST_STD_VER > 11 { typedef std::pair<int, short> P; constexpr P p1(3, 4); diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp index 6d61c47ffbf0..47b4c06134d9 100644 --- a/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp +++ b/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp @@ -18,7 +18,9 @@ #include <utility> #include <cassert> -#if __cplusplus > 201103L +#include "test_macros.h" + +#if TEST_STD_VER > 11 struct S { std::pair<int, int> a; int k; @@ -41,7 +43,7 @@ int main() assert(std::get<1>(p) == 6); } -#if __cplusplus > 201103L +#if TEST_STD_VER > 11 { static_assert(S().k == 1, ""); static_assert(std::get<1>(getP()) == 4, ""); diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp index 27194effe5c3..f0d55a661822 100644 --- a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 #include <utility> #include <complex> @@ -14,11 +15,7 @@ int main() { -#if _LIBCPP_STD_VER > 11 typedef std::complex<float> cf; auto t1 = std::make_pair<int, double> ( 42, 3.4 ); assert (( std::get<cf>(t1) == cf {1,2} )); // no such type -#else -#error -#endif } diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp index f9e3942d7e77..72e637592483 100644 --- a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 #include <utility> #include <complex> @@ -14,11 +15,7 @@ int main() { -#if _LIBCPP_STD_VER > 11 typedef std::complex<float> cf; auto t1 = std::make_pair<int, int> ( 42, 43 ); assert ( std::get<int>(t1) == 42 ); // two ints -#else -#error -#endif } diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp index 484347345747..d5179e4355b9 100644 --- a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 #include <utility> #include <complex> @@ -14,11 +15,7 @@ int main() { -#if _LIBCPP_STD_VER > 11 typedef std::unique_ptr<int> upint; std::pair<upint, int> t(upint(new int(4)), 23); upint p = std::get<upint>(t); -#else -#error -#endif } diff --git a/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp index 4b54f717045a..1117db3297b8 100644 --- a/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp @@ -16,6 +16,8 @@ #include <utility> #include <cassert> +#include "test_macros.h" + int main() { { @@ -25,10 +27,7 @@ int main() assert(p2.first == 3); assert(p2.second == 4); } - - static_assert((std::is_trivially_copy_constructible<std::pair<int, int> >::value), ""); - -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef std::pair<int, short> P1; constexpr P1 p1(3, 4); diff --git a/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp index d83328b8f2d0..97182d24d021 100644 --- a/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -13,9 +13,15 @@ // constexpr pair(); +// This test doesn't pass due to a constexpr bug in GCC 4.9 that fails +// to initialize any type without a user provided constructor in a constant +// expression (ie float). +// XFAIL: gcc-4.9 + // NOTE: The SFINAE on the default constructor is tested in // default-sfinae.pass.cpp + #include <utility> #include <type_traits> #include <cassert> diff --git a/test/std/utilities/utility/pairs/pairs.pair/move_ctor.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/move_ctor.pass.cpp new file mode 100644 index 000000000000..06cb5e5658c9 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/move_ctor.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <utility> + +// template <class T1, class T2> struct pair + +// pair(pair&&) = default; + +#include <utility> +#include <memory> +#include <cassert> + +#include "test_macros.h" + +struct Dummy { + Dummy(Dummy const&) = delete; + Dummy(Dummy &&) = default; +}; + +int main() +{ + { + typedef std::pair<int, short> P1; + static_assert(std::is_move_constructible<P1>::value, ""); + P1 p1(3, 4); + P1 p2 = std::move(p1); + assert(p2.first == 3); + assert(p2.second == 4); + } + { + using P = std::pair<Dummy, int>; + static_assert(!std::is_copy_constructible<P>::value, ""); + static_assert(std::is_move_constructible<P>::value, ""); + } +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp index 0ad5786bce29..dfea61eeacdb 100644 --- a/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp @@ -17,7 +17,7 @@ #include <cassert> struct S { - int i; + int i; S() : i(0) {} S(int j) : i(j) {} S * operator& () { assert(false); return this; } diff --git a/test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp new file mode 100644 index 000000000000..53cf56700df8 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair(pair const&) = default; +// pair(pair&&) = default; + +// Doesn't pass due to use of is_trivially_* trait. +// XFAIL: gcc-4.9 + +#include <utility> +#include <cassert> + +#include "test_macros.h" + +struct Dummy { + Dummy(Dummy const&) = delete; + Dummy(Dummy &&) = default; +}; + +int main() +{ + typedef std::pair<int, short> P; + { + static_assert(std::is_copy_constructible<P>::value, ""); + static_assert(std::is_trivially_copy_constructible<P>::value, ""); + } +#if TEST_STD_VER >= 11 + { + static_assert(std::is_move_constructible<P>::value, ""); + static_assert(std::is_trivially_move_constructible<P>::value, ""); + } + { + using P1 = std::pair<Dummy, int>; + static_assert(!std::is_copy_constructible<P1>::value, ""); + static_assert(!std::is_trivially_copy_constructible<P1>::value, ""); + static_assert(std::is_move_constructible<P1>::value, ""); + static_assert(std::is_trivially_move_constructible<P1>::value, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp index 48e09735abb0..4a6d71e7b9c8 100644 --- a/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp @@ -23,7 +23,7 @@ int main() assert(p1.first == 3); assert(p1.second == 4); } - + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef std::pair<std::unique_ptr<int>, short> P1; diff --git a/test/std/utilities/utility/version.pass.cpp b/test/std/utilities/utility/synopsis.pass.cpp index 77d145d94457..5f5b4eeaad52 100644 --- a/test/std/utilities/utility/version.pass.cpp +++ b/test/std/utilities/utility/synopsis.pass.cpp @@ -8,13 +8,14 @@ //===----------------------------------------------------------------------===// // <utility> +// XFAIL: c++98, c++03 -#include <utility> +// #include <initializer_list> -#ifndef _LIBCPP_VERSION -#error _LIBCPP_VERSION not defined -#endif +#include <utility> int main() { + std::initializer_list<int> x; } + diff --git a/test/std/utilities/utility/utility.swap/swap.pass.cpp b/test/std/utilities/utility/utility.swap/swap.pass.cpp index 8606611f6603..c9c9f3b52760 100644 --- a/test/std/utilities/utility/utility.swap/swap.pass.cpp +++ b/test/std/utilities/utility/utility.swap/swap.pass.cpp @@ -16,38 +16,88 @@ #include <utility> #include <cassert> -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #include <memory> -#endif -void -test() -{ - int i = 1; - int j = 2; - std::swap(i, j); - assert(i == 2); - assert(j == 1); -} +#include "test_macros.h" -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if TEST_STD_VER >= 11 +struct CopyOnly { + CopyOnly() {} + CopyOnly(CopyOnly const&) noexcept {} + CopyOnly& operator=(CopyOnly const&) { return *this; } +}; -void -test1() -{ - std::unique_ptr<int> i(new int(1)); - std::unique_ptr<int> j(new int(2)); - std::swap(i, j); - assert(*i == 2); - assert(*j == 1); -} +struct MoveOnly { + MoveOnly() {} + MoveOnly(MoveOnly&&) {} + MoveOnly& operator=(MoveOnly&&) noexcept { return *this; } +}; + +struct NoexceptMoveOnly { + NoexceptMoveOnly() {} + NoexceptMoveOnly(NoexceptMoveOnly&&) noexcept {} + NoexceptMoveOnly& operator=(NoexceptMoveOnly&&) noexcept { return *this; } +}; + +struct NotMoveConstructible { + NotMoveConstructible& operator=(NotMoveConstructible&&) { return *this; } +private: + NotMoveConstructible(NotMoveConstructible&&); +}; + +struct NotMoveAssignable { + NotMoveAssignable(NotMoveAssignable&&); +private: + NotMoveAssignable& operator=(NotMoveAssignable&&); +}; + +template <class Tp> +auto can_swap_test(int) -> decltype(std::swap(std::declval<Tp>(), std::declval<Tp>())); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class Tp> +auto can_swap_test(...) -> std::false_type; + +template <class Tp> +constexpr bool can_swap() { + return std::is_same<decltype(can_swap_test<Tp>(0)), void>::value; +} +#endif int main() { - test(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - test1(); + + { + int i = 1; + int j = 2; + std::swap(i, j); + assert(i == 2); + assert(j == 1); + } +#if TEST_STD_VER >= 11 + { + + std::unique_ptr<int> i(new int(1)); + std::unique_ptr<int> j(new int(2)); + std::swap(i, j); + assert(*i == 2); + assert(*j == 1); + + } + { + // test that the swap + static_assert(can_swap<CopyOnly&>(), ""); + static_assert(can_swap<MoveOnly&>(), ""); + static_assert(can_swap<NoexceptMoveOnly&>(), ""); + + static_assert(!can_swap<NotMoveConstructible&>(), ""); + static_assert(!can_swap<NotMoveAssignable&>(), ""); + + CopyOnly c; + MoveOnly m; + NoexceptMoveOnly nm; + static_assert(!noexcept(std::swap(c, c)), ""); + static_assert(!noexcept(std::swap(m, m)), ""); + static_assert(noexcept(std::swap(nm, nm)), ""); + } #endif } diff --git a/test/std/utilities/utility/utility.swap/swap_array.pass.cpp b/test/std/utilities/utility/utility.swap/swap_array.pass.cpp index b1209c3c3651..ad39934b20ca 100644 --- a/test/std/utilities/utility/utility.swap/swap_array.pass.cpp +++ b/test/std/utilities/utility/utility.swap/swap_array.pass.cpp @@ -16,50 +16,86 @@ #include <utility> #include <cassert> -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #include <memory> -#endif -void -test() -{ - int i[3] = {1, 2, 3}; - int j[3] = {4, 5, 6}; - std::swap(i, j); - assert(i[0] == 4); - assert(i[1] == 5); - assert(i[2] == 6); - assert(j[0] == 1); - assert(j[1] == 2); - assert(j[2] == 3); -} +#include "test_macros.h" -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -void -test1() -{ - std::unique_ptr<int> i[3]; - for (int k = 0; k < 3; ++k) - i[k].reset(new int(k+1)); - std::unique_ptr<int> j[3]; - for (int k = 0; k < 3; ++k) - j[k].reset(new int(k+4)); - std::swap(i, j); - assert(*i[0] == 4); - assert(*i[1] == 5); - assert(*i[2] == 6); - assert(*j[0] == 1); - assert(*j[1] == 2); - assert(*j[2] == 3); +#if TEST_STD_VER >= 11 +struct CopyOnly { + CopyOnly() {} + CopyOnly(CopyOnly const&) noexcept {} + CopyOnly& operator=(CopyOnly const&) { return *this; } +}; + + +struct NoexceptMoveOnly { + NoexceptMoveOnly() {} + NoexceptMoveOnly(NoexceptMoveOnly&&) noexcept {} + NoexceptMoveOnly& operator=(NoexceptMoveOnly&&) noexcept { return *this; } +}; + +struct NotMoveConstructible { + NotMoveConstructible() {} + NotMoveConstructible& operator=(NotMoveConstructible&&) { return *this; } +private: + NotMoveConstructible(NotMoveConstructible&&); +}; + +template <class Tp> +auto can_swap_test(int) -> decltype(std::swap(std::declval<Tp>(), std::declval<Tp>())); + +template <class Tp> +auto can_swap_test(...) -> std::false_type; + +template <class Tp> +constexpr bool can_swap() { + return std::is_same<decltype(can_swap_test<Tp>(0)), void>::value; } +#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES int main() { - test(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - test1(); + { + int i[3] = {1, 2, 3}; + int j[3] = {4, 5, 6}; + std::swap(i, j); + assert(i[0] == 4); + assert(i[1] == 5); + assert(i[2] == 6); + assert(j[0] == 1); + assert(j[1] == 2); + assert(j[2] == 3); + } +#if TEST_STD_VER >= 11 + { + std::unique_ptr<int> i[3]; + for (int k = 0; k < 3; ++k) + i[k].reset(new int(k+1)); + std::unique_ptr<int> j[3]; + for (int k = 0; k < 3; ++k) + j[k].reset(new int(k+4)); + std::swap(i, j); + assert(*i[0] == 4); + assert(*i[1] == 5); + assert(*i[2] == 6); + assert(*j[0] == 1); + assert(*j[1] == 2); + assert(*j[2] == 3); + } + { + using CA = CopyOnly[42]; + using MA = NoexceptMoveOnly[42]; + using NA = NotMoveConstructible[42]; + static_assert(can_swap<CA&>(), ""); + static_assert(can_swap<MA&>(), ""); + static_assert(!can_swap<NA&>(), ""); + + CA ca; + MA ma; + static_assert(!noexcept(std::swap(ca, ca)), ""); + static_assert(noexcept(std::swap(ma, ma)), ""); + } #endif } |