From 5a83710e371fe68a06e6e3876c6a2c8b820a8976 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 20 Dec 2014 01:40:03 +0000 Subject: Move test into test/std subdirectory. llvm-svn: 224658 --- .../tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp | 49 +++++++ .../tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp | 144 +++++++++++++++++++++ .../tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp | 79 +++++++++++ .../tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp | 139 ++++++++++++++++++++ .../tuple.cnstr/alloc_const_Types.pass.cpp | 74 +++++++++++ .../tuple.cnstr/alloc_const_pair.pass.cpp | 57 ++++++++ .../tuple.cnstr/alloc_convert_copy.pass.cpp | 67 ++++++++++ .../tuple.cnstr/alloc_convert_move.pass.cpp | 82 ++++++++++++ .../tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp | 76 +++++++++++ .../tuple.tuple/tuple.cnstr/alloc_move.pass.cpp | 75 +++++++++++ .../tuple.cnstr/alloc_move_pair.pass.cpp | 53 ++++++++ .../tuple.tuple/tuple.cnstr/const_Types.fail.cpp | 25 ++++ .../tuple.tuple/tuple.cnstr/const_Types.pass.cpp | 130 +++++++++++++++++++ .../tuple.tuple/tuple.cnstr/const_Types2.fail.cpp | 25 ++++ .../tuple.tuple/tuple.cnstr/const_pair.pass.cpp | 42 ++++++ .../tuple.tuple/tuple.cnstr/convert_copy.pass.cpp | 115 ++++++++++++++++ .../tuple.tuple/tuple.cnstr/convert_move.pass.cpp | 82 ++++++++++++ .../tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp | 28 ++++ .../tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp | 63 +++++++++ .../tuple/tuple.tuple/tuple.cnstr/default.pass.cpp | 91 +++++++++++++ .../tuple/tuple.tuple/tuple.cnstr/move.pass.cpp | 69 ++++++++++ .../tuple.tuple/tuple.cnstr/move_pair.pass.cpp | 46 +++++++ .../tuple_array_template_depth.pass.cpp | 34 +++++ 23 files changed, 1645 insertions(+) create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp create mode 100644 libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp (limited to 'libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr') diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp new file mode 100644 index 00000000000..c2c00f2e13b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// explicit tuple(UTypes&&... u); + +/* + This is testing an extension whereby only Types having an explicit conversion + from UTypes are bound by the explicit tuple constructor. +*/ + +#include +#include + +class MoveOnly +{ + MoveOnly(const MoveOnly&); + MoveOnly& operator=(const MoveOnly&); + + int data_; +public: + explicit MoveOnly(int data = 1) : data_(data) {} + MoveOnly(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} + + bool operator==(const MoveOnly& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly& x) const {return data_ < x.data_;} +}; + +int main() +{ + { + std::tuple t = 1; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp new file mode 100644 index 00000000000..3d8b194eb32 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// explicit tuple(UTypes&&... u); + +#include +#include +#include + +#include "../MoveOnly.h" + +#if _LIBCPP_STD_VER > 11 + +struct Empty {}; +struct A +{ + int id_; + explicit constexpr A(int i) : id_(i) {} +}; + +#endif + +struct NoDefault { NoDefault() = delete; }; + +// Make sure the _Up... constructor SFINAEs out when the types that +// are not explicitly initialized are not all default constructible. +// Otherwise, std::is_constructible would return true but instantiating +// the constructor would fail. +void test_default_constructible_extension_sfinae() +{ + { + typedef std::tuple Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple type. + typedef std::tuple Tuple; + typedef std::tuple NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple Tuple; + typedef std::tuple NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple t(MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple t(MoveOnly(0), + MoveOnly(1), + MoveOnly(2)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + // extensions + { + std::tuple t(MoveOnly(0), + MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == MoveOnly()); + assert(std::get<2>(t) == MoveOnly()); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple t0{Empty()}; + } + { + constexpr std::tuple t(3, 2); + static_assert(std::get<0>(t).id_ == 3, ""); + } +#endif + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp new file mode 100644 index 00000000000..606c60996d6 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a); + +#include +#include + +#include "DefaultOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<> t(std::allocator_arg, A1()); + } + { + std::tuple t(std::allocator_arg, A1()); + assert(std::get<0>(t) == 0); + } + { + std::tuple t(std::allocator_arg, A1()); + assert(std::get<0>(t) == DefaultOnly()); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple t(std::allocator_arg, A1(5)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first()); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple t(std::allocator_arg, A1(5)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + std::tuple t(std::allocator_arg, A1(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple t(std::allocator_arg, + A1(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple t(std::allocator_arg, + A2(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(!alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + assert(!alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last()); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp new file mode 100644 index 00000000000..00bc5e05402 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, UTypes&&...); + +#include +#include + +#include "../MoveOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct NoDefault { NoDefault() = delete; }; + +// Make sure the _Up... constructor SFINAEs out when the types that +// are not explicitly initialized are not all default constructible. +// Otherwise, std::is_constructible would return true but instantiating +// the constructor would fail. +void test_default_constructible_extension_sfinae() +{ + { + typedef std::tuple Tuple; + + static_assert(!std::is_constructible< + Tuple, + std::allocator_arg_t, A1, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + std::allocator_arg_t, A1, MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple Tuple; + + static_assert(!std::is_constructible< + std::tuple, + std::allocator_arg_t, A1, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + std::tuple, + std::allocator_arg_t, A1, MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple + typedef std::tuple Tuple; + typedef std::tuple NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple Tuple; + typedef std::tuple NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple t(std::allocator_arg, A1(), MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple t(std::allocator_arg, A1(), + MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple t(std::allocator_arg, A1(), + MoveOnly(0), + 1, 2); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple t(std::allocator_arg, + A1(5), 1, 2, 3); + assert(std::get<0>(t) == 1); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } + // extensions + { + std::tuple t(std::allocator_arg, A1(), + 0, 1); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple t(std::allocator_arg, A1(), + 0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == MoveOnly()); + assert(std::get<2>(t) == MoveOnly()); + } + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp new file mode 100644 index 00000000000..5f6a586f67a --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, const Types&...); + +#include +#include + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple t(std::allocator_arg, A1(), 3); + assert(std::get<0>(t) == 3); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple t(std::allocator_arg, A1(5), alloc_first(3)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first(3)); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple t(std::allocator_arg, A1(5), alloc_last(3)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + std::tuple t(std::allocator_arg, A1(5), + 10, alloc_first(15)); + assert(std::get<0>(t) == 10); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(15)); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple t(std::allocator_arg, + A1(5), 1, alloc_first(2), + alloc_last(3)); + assert(std::get<0>(t) == 1); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple t(std::allocator_arg, + A2(5), 1, alloc_first(2), + alloc_last(3)); + assert(std::get<0>(t) == 1); + assert(!alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(!alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp new file mode 100644 index 00000000000..0b210e5901f --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, const pair&); + +#include +#include +#include + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::pair T0; + typedef std::tuple T1; + T0 t0(2, 3); + T1 t1(std::allocator_arg, A1(5), t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair T0; + typedef std::tuple T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair T0; + typedef std::tuple T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp new file mode 100644 index 00000000000..fd127caeb80 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, const tuple&); + +#include +#include + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5); + T1 t1(std::allocator_arg, A1(), t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(1.5, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 1); + assert(std::get<1>(t1) == 2); + assert(std::get<2>(t1) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp new file mode 100644 index 00000000000..b420588b03b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, tuple&&); + +#include +#include +#include +#include + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple> T0; + typedef std::tuple> T1; + T0 t0(std::unique_ptr(new D(3))); + T1 t1(std::allocator_arg, A1(5), std::move(t0)); + assert(std::get<0>(t1)->id_ == 3); + } + { + typedef std::tuple> T0; + typedef std::tuple> T1; + T0 t0(2, std::unique_ptr(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } + { + typedef std::tuple> T0; + typedef std::tuple> T1; + T0 t0(1, 2, std::unique_ptr(new D(3))); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 1); + assert(std::get<1>(t1) == 2); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp new file mode 100644 index 00000000000..568ed9700db --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, const tuple&); + +#include +#include + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t(std::allocator_arg, A1(), t0); + } + { + typedef std::tuple T; + T t0(2); + T t(std::allocator_arg, A1(), t0); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple T; + T t0(2); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple T; + T t0(2); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1(5), t0); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple T; + T t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 3); + } + { + typedef std::tuple T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp new file mode 100644 index 00000000000..575a99404eb --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, tuple&&); + +#include +#include + +#include "../MoveOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t(std::allocator_arg, A1(), std::move(t0)); + } + { + typedef std::tuple T; + T t0(MoveOnly(0)); + T t(std::allocator_arg, A1(), std::move(t0)); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple T; + T t0(1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple T; + T t0(1); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple T; + T t0(0 ,1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp new file mode 100644 index 00000000000..31c605ea065 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template +// tuple(allocator_arg_t, const Alloc& a, pair&&); + +#include +#include +#include +#include + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair> T0; + typedef std::tuple> T1; + T0 t0(2, std::unique_ptr(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp new file mode 100644 index 00000000000..e8a78d1983e --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// explicit tuple(const T&...); + +#include +#include +#include + +int main() +{ + { + std::tuple t = 0; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp new file mode 100644 index 00000000000..ca53cd3c519 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp @@ -0,0 +1,130 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// explicit tuple(const T&...); + +#include +#include +#include + + +template +struct never { + enum { value = 0 }; +}; + +struct NoValueCtor +{ + NoValueCtor() : id(++count) {} + NoValueCtor(NoValueCtor const & other) : id(other.id) { ++count; } + + // The constexpr is required to make is_constructible instantiate this template. + // The explicit is needed to test-around a similar bug with is_convertible. + template + constexpr explicit NoValueCtor(T) + { static_assert(never::value, "This should not be instantiated"); } + + static int count; + int id; +}; + +int NoValueCtor::count = 0; + + +struct NoValueCtorEmpty +{ + NoValueCtorEmpty() {} + NoValueCtorEmpty(NoValueCtorEmpty const &) {} + + template + constexpr explicit NoValueCtorEmpty(T) + { static_assert(never::value, "This should not be instantiated"); } +}; + +int main() +{ + { + std::tuple t(2); + assert(std::get<0>(t) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple t(2); + static_assert(std::get<0>(t) == 2, ""); + } + { + constexpr std::tuple t; + static_assert(std::get<0>(t) == 0, ""); + } +#endif + { + std::tuple t(2, 0); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple t(2, nullptr); + static_assert(std::get<0>(t) == 2, ""); + static_assert(std::get<1>(t) == nullptr, ""); + } +#endif + { + std::tuple t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + } + // __tuple_leaf uses is_constructible to disable its explicit converting + // constructor overload __tuple_leaf(U &&). Evaluating is_constructible can cause a compile error. + // This overload is evaluated when __tuple_leafs copy or move ctor is called. + // This checks that is_constructible is not evaluated when U == __tuple_leaf. + { + std::tuple t(1, NoValueCtor(), 2, 3); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t).id == 1); + assert(std::get<2>(t) == 2); + assert(std::get<3>(t) == 3); + } + { + std::tuple t(1, NoValueCtorEmpty(), 2, 3); + assert(std::get<0>(t) == 1); + assert(std::get<2>(t) == 2); + assert(std::get<3>(t) == 3); + } + // extensions + { + std::tuple t(2); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + assert(std::get<3>(t) == 0.0); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp new file mode 100644 index 00000000000..4b3359e0a27 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// explicit tuple(const T&...); + +#include +#include +#include + +int main() +{ + { + std::tuple t(2, nullptr, "text"); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp new file mode 100644 index 00000000000..d40196b07ed --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template tuple(const pair& u); + +#include +#include +#include + +int main() +{ + { + typedef std::pair T0; + typedef std::tuple T1; + T0 t0(2.5, 'a'); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == short('a')); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P0; + typedef std::tuple T1; + constexpr P0 p0(2.5, 'a'); + constexpr T1 t1 = p0; + static_assert(std::get<0>(t1) != std::get<0>(p0), ""); + static_assert(std::get<1>(t1) == std::get<1>(p0), ""); + static_assert(std::get<0>(t1) == 2, ""); + static_assert(std::get<1>(t1) == short('a'), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp new file mode 100644 index 00000000000..bcdb9d99b9b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template tuple(const tuple& u); + +#include +#include +#include + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +#if _LIBCPP_STD_VER > 11 + +struct A +{ + int id_; + + constexpr A(int i) : id_(i) {} + friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;} +}; + +struct C +{ + int id_; + + constexpr explicit C(int i) : id_(i) {} + friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;} +}; + +#endif + +int main() +{ + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T0; + typedef std::tuple T1; + constexpr T0 t0(2.5); + constexpr T1 t1 = t0; + static_assert(std::get<0>(t1) == 2, ""); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + constexpr T0 t0(2); + constexpr T1 t1{t0}; + static_assert(std::get<0>(t1) == C(2), ""); + } +#endif + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a'); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a', D(3)); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a', d); + T1 t1 = t0; + d.id_ = 2; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a', 3); + T1 t1(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp new file mode 100644 index 00000000000..ff19c2eecf6 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template tuple(tuple&& u); + +#include +#include +#include +#include + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a'); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a', D(3)); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + typedef std::tuple T0; + typedef std::tuple T1; + T0 t0(2.5, 'a', d); + T1 t1 = std::move(t0); + d.id_ = 2; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple> T0; + typedef std::tuple> T1; + T0 t0(2.5, 'a', std::unique_ptr(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp new file mode 100644 index 00000000000..8b8ec0ca53f --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// tuple(const tuple& u) = default; + +#include +#include + +#include "../MoveOnly.h" + +int main() +{ + { + typedef std::tuple T; + T t0(MoveOnly(2)); + T t = t0; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..fd953f84340 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// tuple(const tuple& u) = default; + +#include +#include +#include + +struct Empty {}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = t0; + } + { + typedef std::tuple T; + T t0(2); + T t = t0; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple T; + T t0(2, 'a'); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + } + { + typedef std::tuple T; + const T t0(2, 'a', "some text"); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + assert(std::get<2>(t) == "some text"); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T; + constexpr T t0(2); + constexpr T t = t0; + static_assert(std::get<0>(t) == 2, ""); + } + { + typedef std::tuple T; + constexpr T t0; + constexpr T t = t0; + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp new file mode 100644 index 00000000000..9cde90da3f5 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// constexpr tuple(); + +#include +#include +#include +#include + +#include "DefaultOnly.h" + +struct NoDefault { + NoDefault() = delete; + explicit NoDefault(int) { } +}; + +struct NoExceptDefault { + NoExceptDefault() noexcept = default; +}; + +struct ThrowingDefault { + ThrowingDefault() { } +}; + +int main() +{ + { + std::tuple<> t; + } + { + std::tuple t; + assert(std::get<0>(t) == 0); + } + { + std::tuple t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + assert(std::get<3>(t) == DefaultOnly()); + } + { + // See bug #21157. + static_assert(!std::is_default_constructible>(), ""); + static_assert(!std::is_default_constructible>(), ""); + static_assert(!std::is_default_constructible>(), ""); + } + { + static_assert(noexcept(std::tuple()), ""); + static_assert(noexcept(std::tuple()), ""); + + static_assert(!noexcept(std::tuple()), ""); + static_assert(!noexcept(std::tuple()), ""); + static_assert(!noexcept(std::tuple()), ""); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::tuple<> t; + } + { + constexpr std::tuple t; + assert(std::get<0>(t) == 0); + } + { + constexpr std::tuple t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp new file mode 100644 index 00000000000..8dc7d21ec28 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// tuple(tuple&& u); + +#include +#include + +#include "../MoveOnly.h" + +struct ConstructsWithTupleLeaf +{ + ConstructsWithTupleLeaf() {} + + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} + + template + ConstructsWithTupleLeaf(T t) + { assert(false); } +}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = std::move(t0); + } + { + typedef std::tuple T; + T t0(MoveOnly(0)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple T; + T t0(MoveOnly(0), MoveOnly(1)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + // A bug in tuple caused __tuple_leaf to use its explicit converting constructor + // as its move constructor. This tests that ConstructsWithTupleLeaf is not called + // (w/ __tuple_leaf) + { + typedef std::tuple d_t; + d_t d((ConstructsWithTupleLeaf())); + d_t d2(static_cast(d)); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp new file mode 100644 index 00000000000..05d78459cec --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template tuple(pair&& u); + +#include +#include +#include +#include + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair> T0; + typedef std::tuple> T1; + T0 t0(2.5, std::unique_ptr(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp new file mode 100644 index 00000000000..65a1c701c51 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template class tuple; + +// template > +// tuple(Tuple &&); +// +// template > +// tuple(Tuple &&); + +// This test checks that we do not evaluate __make_tuple_types +// on the array. + +#include +#include + +// Use 1256 to try and blow the template instantiation depth for all compilers. +typedef std::array array_t; +typedef std::tuple tuple_t; + +int main() +{ + array_t arr; + tuple_t tup(arr); +} -- cgit v1.2.3