diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/utilities/tuple/tuple.tuple/tuple.cnstr | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) |
Notes
Diffstat (limited to 'test/std/utilities/tuple/tuple.tuple/tuple.cnstr')
23 files changed, 1714 insertions, 0 deletions
diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp new file mode 100644 index 0000000000000..b9497bea56771 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +// UNSUPPORTED: c++98, c++03 + +/* + This is testing an extension whereby only Types having an explicit conversion + from UTypes are bound by the explicit tuple constructor. +*/ + +#include <tuple> +#include <cassert> + +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<MoveOnly> t = 1; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp new file mode 100644 index 0000000000000..817cc8f109905 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> +#include <type_traits> + +#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<MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple<MoveOnly, MoveOnly, NoDefault> 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<MoveOnly, NoDefault> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> 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<MoveOnly, int> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> 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<MoveOnly> t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple<MoveOnly, MoveOnly> t(MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> 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<MoveOnly, MoveOnly, MoveOnly> 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<MoveOnly, MoveOnly, MoveOnly> 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<Empty> t0{Empty()}; + } + { + constexpr std::tuple<A, A> 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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp new file mode 100644 index 0000000000000..39776822cbda4 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "DefaultOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<> t(std::allocator_arg, A1<int>()); + } + { + std::tuple<int> t(std::allocator_arg, A1<int>()); + assert(std::get<0>(t) == 0); + } + { + std::tuple<DefaultOnly> t(std::allocator_arg, A1<int>()); + assert(std::get<0>(t) == DefaultOnly()); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first()); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first> t(std::allocator_arg, A1<int>(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<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(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<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg, + A2<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp new file mode 100644 index 0000000000000..3929965cd2735 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, UTypes&&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#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<MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple + typedef std::tuple<MoveOnly, NoDefault> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple<MoveOnly, int> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple<MoveOnly> t(std::allocator_arg, A1<int>(), MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple<MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 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<int, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(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<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 0, 1); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp new file mode 100644 index 0000000000000..0f68926376f24 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, const Types&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<int> t(std::allocator_arg, A1<int>(), 3); + assert(std::get<0>(t) == 3); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5), alloc_first(3)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first(3)); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5), alloc_last(3)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + std::tuple<int, alloc_first> t(std::allocator_arg, A1<int>(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<int, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(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<int, alloc_first, alloc_last> t(std::allocator_arg, + A2<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp new file mode 100644 index 0000000000000..c5941618180d3 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class U1, class U2> +// tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::pair<double, int> T0; + typedef std::tuple<int, double> T1; + T0 t0(2, 3); + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair<int, int> T0; + typedef std::tuple<alloc_first, double> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair<int, int> T0; + typedef std::tuple<alloc_first, alloc_last> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp new file mode 100644 index 0000000000000..8acfde7a98eb1 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1(std::allocator_arg, A1<int>(), t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<int> T0; + typedef std::tuple<alloc_first> T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<int, int> T0; + typedef std::tuple<alloc_first, alloc_last> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(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<double, int, int> T0; + typedef std::tuple<int, alloc_first, alloc_last> T1; + T0 t0(1.5, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp new file mode 100644 index 0000000000000..c862d3b64d56f --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +#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<int> T0; + typedef std::tuple<alloc_first> T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<std::unique_ptr<D>> T0; + typedef std::tuple<std::unique_ptr<B>> T1; + T0 t0(std::unique_ptr<D>(new D(3))); + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(std::get<0>(t1)->id_ == 3); + } + { + typedef std::tuple<int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(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<int, int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1; + T0 t0(1, 2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp new file mode 100644 index 0000000000000..14e127e59ba91 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, const tuple&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#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<int>(), t0); + } + { + typedef std::tuple<int> T; + T t0(2); + T t(std::allocator_arg, A1<int>(), t0); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_first> T; + T t0(2); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_last> T; + T t0(2); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_first, alloc_last> T; + T t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(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<int, alloc_first, alloc_last> T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp new file mode 100644 index 0000000000000..54d3f7ee0c079 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, tuple&&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#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<int>(), std::move(t0)); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t(std::allocator_arg, A1<int>(), std::move(t0)); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<alloc_first> T; + T t0(1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple<alloc_last> T; + T t0(1); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple<MoveOnly, alloc_first> T; + T t0(0 ,1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, alloc_first, alloc_last> T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp new file mode 100644 index 0000000000000..03e9ab2f60269 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class U1, class U2> +// tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +#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<int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp new file mode 100644 index 0000000000000..00e2af265b360 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + std::tuple<int*> t = 0; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp new file mode 100644 index 0000000000000..bbadf8de16001 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + + +template <class ...> +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 <class T> + constexpr explicit NoValueCtor(T) + { static_assert(never<T>::value, "This should not be instantiated"); } + + static int count; + int id; +}; + +int NoValueCtor::count = 0; + + +struct NoValueCtorEmpty +{ + NoValueCtorEmpty() {} + NoValueCtorEmpty(NoValueCtorEmpty const &) {} + + template <class T> + constexpr explicit NoValueCtorEmpty(T) + { static_assert(never<T>::value, "This should not be instantiated"); } +}; + +int main() +{ + { + std::tuple<int> t(2); + assert(std::get<0>(t) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<int> t(2); + static_assert(std::get<0>(t) == 2, ""); + } + { + constexpr std::tuple<int> t; + static_assert(std::get<0>(t) == 0, ""); + } +#endif + { + std::tuple<int, char*> t(2, 0); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<int, char*> t(2, nullptr); + static_assert(std::get<0>(t) == 2, ""); + static_assert(std::get<1>(t) == nullptr, ""); + } +#endif + { + std::tuple<int, char*> t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple<int, char*, std::string> t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + } + // __tuple_leaf<T> uses is_constructible<T, U> 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<int, NoValueCtor, int, int> 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<int, NoValueCtorEmpty, int, int> 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<int, char*, std::string> t(2); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string> t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string, double> 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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp new file mode 100644 index 0000000000000..68b3fbd0dd9e4 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + std::tuple<int, char*, std::string, double&> t(2, nullptr, "text"); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp new file mode 100644 index 0000000000000..740b6589e5114 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> tuple(const pair<U1, U2>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<double, char> T0; + typedef std::tuple<int, short> 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<double, char> P0; + typedef std::tuple<int, short> 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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp new file mode 100644 index 0000000000000..5ad4f9227f481 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> tuple(const tuple<UTypes...>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <string> +#include <cassert> + +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<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<double> T0; + typedef std::tuple<A> T1; + constexpr T0 t0(2.5); + constexpr T1 t1 = t0; + static_assert(std::get<0>(t1) == 2, ""); + } + { + typedef std::tuple<int> T0; + typedef std::tuple<C> T1; + constexpr T0 t0(2); + constexpr T1 t1{t0}; + static_assert(std::get<0>(t1) == C(2), ""); + } +#endif + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> 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<double, char, D> T0; + typedef std::tuple<int, int, B> 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<double, char, D&> T0; + typedef std::tuple<int, int, B&> 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<double, char, int> T0; + typedef std::tuple<int, int, B> 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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp new file mode 100644 index 0000000000000..3a6abd3a95af4 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> tuple(tuple<UTypes...>&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +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<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> 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<double, char, D> T0; + typedef std::tuple<int, int, B> 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<double, char, D&> T0; + typedef std::tuple<int, int, B&> 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<double, char, std::unique_ptr<D>> T0; + typedef std::tuple<int, int, std::unique_ptr<B>> T1; + T0 t0(2.5, 'a', std::unique_ptr<D>(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/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp new file mode 100644 index 0000000000000..1937f49efa76a --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(2)); + T t = t0; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp new file mode 100644 index 0000000000000..783c9d1f06a8b --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +struct Empty {}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = t0; + ((void)t); // Prevent unused warning + } + { + typedef std::tuple<int> T; + T t0(2); + T t = t0; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<int, char> T; + T t0(2, 'a'); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + } + { + typedef std::tuple<int, char, std::string> 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<int> T; + constexpr T t0(2); + constexpr T t = t0; + static_assert(std::get<0>(t) == 2, ""); + } + { + typedef std::tuple<Empty> T; + constexpr T t0; + constexpr T t = t0; + constexpr Empty e = std::get<0>(t); + ((void)e); // Prevent unused warning + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp new file mode 100644 index 0000000000000..d282c9c68a42d --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// constexpr tuple(); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> +#include <type_traits> + +#include "DefaultOnly.h" + +struct NoDefault { + NoDefault() = delete; + explicit NoDefault(int) { } +}; + +struct NoExceptDefault { + NoExceptDefault() noexcept = default; +}; + +struct ThrowingDefault { + ThrowingDefault() { } +}; + +struct IllFormedDefault { + IllFormedDefault(int x) : value(x) {} + template <bool Pred = false> + constexpr IllFormedDefault() { + static_assert(Pred, + "The default constructor should not be instantiated"); + } + int value; +}; + +int main() +{ + { + std::tuple<> t; + } + { + std::tuple<int> t; + assert(std::get<0>(t) == 0); + } + { + std::tuple<int, char*> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple<int, char*, std::string> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string, DefaultOnly> 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<std::tuple<NoDefault>>(), ""); + static_assert(!std::is_default_constructible<std::tuple<DefaultOnly, NoDefault>>(), ""); + static_assert(!std::is_default_constructible<std::tuple<NoDefault, DefaultOnly, NoDefault>>(), ""); + } + { + static_assert(noexcept(std::tuple<NoExceptDefault>()), ""); + static_assert(noexcept(std::tuple<NoExceptDefault, NoExceptDefault>()), ""); + + static_assert(!noexcept(std::tuple<ThrowingDefault, NoExceptDefault>()), ""); + static_assert(!noexcept(std::tuple<NoExceptDefault, ThrowingDefault>()), ""); + static_assert(!noexcept(std::tuple<ThrowingDefault, ThrowingDefault>()), ""); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::tuple<> t; + } + { + constexpr std::tuple<int> t; + assert(std::get<0>(t) == 0); + } + { + constexpr std::tuple<int, char*> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } + { + // Check that the SFINAE on the default constructor is not evaluted when + // it isn't needed. If the default constructor is evaluted then this test + // should fail to compile. + IllFormedDefault v(0); + std::tuple<IllFormedDefault> t(v); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp new file mode 100644 index 0000000000000..0cda96846f717 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(tuple&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +#include "MoveOnly.h" + +struct ConstructsWithTupleLeaf +{ + ConstructsWithTupleLeaf() {} + + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} + + template <class T> + ConstructsWithTupleLeaf(T t) + { assert(false); } +}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = std::move(t0); + ((void)t); // Prevent unused warning + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> 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<MoveOnly, MoveOnly, MoveOnly> 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<ConstructsWithTupleLeaf> d_t; + d_t d((ConstructsWithTupleLeaf())); + d_t d2(static_cast<d_t &&>(d)); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp new file mode 100644 index 0000000000000..2dfbaff6cc1a7 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> tuple(pair<U1, U2>&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +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<double, std::unique_ptr<D>> T0; + typedef std::tuple<int, std::unique_ptr<B>> T1; + T0 t0(2.5, std::unique_ptr<D>(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp new file mode 100644 index 0000000000000..c069a0ba20eae --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Tuple, __tuple_convertible<Tuple, tuple> > +// tuple(Tuple &&); +// +// template <class Tuple, __tuple_constructible<Tuple, tuple> > +// tuple(Tuple &&); + +// This test checks that we do not evaluate __make_tuple_types +// on the array. + +#include <array> +#include <tuple> + +// Use 1256 to try and blow the template instantiation depth for all compilers. +typedef std::array<char, 1256> array_t; +typedef std::tuple<array_t> tuple_t; + +int main() +{ + array_t arr; + tuple_t tup(arr); +} |