diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
| commit | 53a420fba21cf1644972b34dcd811a43cdb8368d (patch) | |
| tree | 66a19f6f8b65215772549a51d688492ab8addc0d /test/std/utilities/tuple/tuple.tuple/tuple.cnstr | |
| parent | b50f1549701eb950921e5d6f2e55ba1a1dadbb43 (diff) | |
Notes
Diffstat (limited to 'test/std/utilities/tuple/tuple.tuple/tuple.cnstr')
13 files changed, 206 insertions, 65 deletions
diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR23256_constrain_UTypes_ctor.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR23256_constrain_UTypes_ctor.pass.cpp index ed3cafadbf08d..a5b3d4415e385 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR23256_constrain_UTypes_ctor.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR23256_constrain_UTypes_ctor.pass.cpp @@ -91,6 +91,8 @@ int main() { } { std::tuple<A&&> t(std::forward_as_tuple(A{})); + ((void)t); std::tuple<ExplicitA&&> t2(std::forward_as_tuple(ExplicitA{})); + ((void)t2); } } diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp new file mode 100644 index 0000000000000..dd9b832423a66 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp @@ -0,0 +1,88 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 TupleLike> tuple(TupleLike&&); // libc++ extension + +// See llvm.org/PR31384 +#include <tuple> +#include <cassert> + +int count = 0; + +struct Explicit { + Explicit() = default; + explicit Explicit(int) {} +}; + +struct Implicit { + Implicit() = default; + Implicit(int) {} +}; + +template<class T> +struct Derived : std::tuple<T> { + using std::tuple<T>::tuple; + template<class U> + operator std::tuple<U>() && { ++count; return {}; } +}; + + +template<class T> +struct ExplicitDerived : std::tuple<T> { + using std::tuple<T>::tuple; + template<class U> + explicit operator std::tuple<U>() && { ++count; return {}; } +}; + +int main() { + { + std::tuple<Explicit> foo = Derived<int>{42}; ((void)foo); + assert(count == 1); + std::tuple<Explicit> bar(Derived<int>{42}); ((void)bar); + assert(count == 2); + } + count = 0; + { + std::tuple<Implicit> foo = Derived<int>{42}; ((void)foo); + assert(count == 1); + std::tuple<Implicit> bar(Derived<int>{42}); ((void)bar); + assert(count == 2); + } + count = 0; + { + static_assert(!std::is_convertible< + ExplicitDerived<int>, std::tuple<Explicit>>::value, ""); + std::tuple<Explicit> bar(ExplicitDerived<int>{42}); ((void)bar); + assert(count == 1); + } + count = 0; + { + // FIXME: Libc++ incorrectly rejects this code. +#ifndef _LIBCPP_VERSION + std::tuple<Implicit> foo = ExplicitDerived<int>{42}; ((void)foo); + static_assert(std::is_convertible< + ExplicitDerived<int>, std::tuple<Implicit>>::value, + "correct STLs accept this"); +#else + static_assert(!std::is_convertible< + ExplicitDerived<int>, std::tuple<Implicit>>::value, + "libc++ incorrectly rejects this"); +#endif + assert(count == 0); + std::tuple<Implicit> bar(ExplicitDerived<int>{42}); ((void)bar); + assert(count == 1); + } + count = 0; + +} 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 index 6ab303c735bec..06284df56642d 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -20,9 +20,11 @@ #include <cassert> #include <type_traits> +#include "test_macros.h" +#include "test_convertible.hpp" #include "MoveOnly.h" -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 struct Empty {}; struct A @@ -123,17 +125,23 @@ int main() // extensions #ifdef _LIBCPP_VERSION { - std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0), - MoveOnly(1)); + using E = MoveOnly; + using Tup = std::tuple<E, E, E>; + // Test that the reduced arity initialization extension is only + // allowed on the explicit constructor. + static_assert(test_convertible<Tup, E, E, E>(), ""); + + Tup t(E(0), E(1)); + static_assert(!test_convertible<Tup, E, E>(), ""); 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)); + + Tup t2(E(0)); + static_assert(!test_convertible<Tup, E>(), ""); assert(std::get<0>(t) == 0); - assert(std::get<1>(t) == MoveOnly()); - assert(std::get<2>(t) == MoveOnly()); + assert(std::get<1>(t) == E()); + assert(std::get<2>(t) == E()); } #endif #if TEST_STD_VER > 11 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 index c5941618180d3..1d0c7b49aaaac 100644 --- 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 @@ -27,8 +27,8 @@ int main() { { - typedef std::pair<double, int> T0; - typedef std::tuple<int, double> T1; + typedef std::pair<long, int> T0; + typedef std::tuple<long long, double> T1; T0 t0(2, 3); T1 t1(std::allocator_arg, A1<int>(5), t0); assert(std::get<0>(t1) == 2); 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 index 36d9f32879cbb..153cd2b3d7cec 100644 --- 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 @@ -37,9 +37,9 @@ struct Implicit { int main() { { - typedef std::tuple<double> T0; - typedef std::tuple<int> T1; - T0 t0(2.5); + typedef std::tuple<long> T0; + typedef std::tuple<long long> T1; + T0 t0(2); T1 t1(std::allocator_arg, A1<int>(), t0); assert(std::get<0>(t1) == 2); } @@ -65,9 +65,9 @@ int main() 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); + typedef std::tuple<long, int, int> T0; + typedef std::tuple<long long, alloc_first, alloc_last> T1; + T0 t0(1, 2, 3); alloc_first::allocator_constructed = false; alloc_last::allocator_constructed = false; T1 t1(std::allocator_arg, A1<int>(5), t0); 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 index 367f19e5d8dd6..0da132fcfc263 100644 --- 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 @@ -19,6 +19,7 @@ #include <string> #include <cassert> +#include "test_macros.h" template <class ...> struct never { @@ -81,12 +82,13 @@ int main() { // check that the literal '0' can implicitly initialize a stored pointer. std::tuple<int*> t = 0; + assert(std::get<0>(t) == nullptr); } { std::tuple<int> t(2); assert(std::get<0>(t) == 2); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { constexpr std::tuple<int> t(2); static_assert(std::get<0>(t) == 2, ""); @@ -101,7 +103,7 @@ int main() assert(std::get<0>(t) == 2); assert(std::get<1>(t) == nullptr); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { constexpr std::tuple<int, char*> t(2, nullptr); static_assert(std::get<0>(t) == 2, ""); 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 index d6d489fd0ea44..bed161a3dcefb 100644 --- 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 @@ -19,23 +19,25 @@ #include <utility> #include <cassert> +#include "test_macros.h" + int main() { { - typedef std::pair<double, char> T0; - typedef std::tuple<int, short> T1; - T0 t0(2.5, 'a'); + typedef std::pair<long, char> T0; + typedef std::tuple<long long, short> T1; + T0 t0(2, 'a'); T1 t1 = t0; assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == short('a')); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { - typedef std::pair<double, char> P0; - typedef std::tuple<int, short> T1; - constexpr P0 p0(2.5, 'a'); + typedef std::pair<long, char> P0; + typedef std::tuple<long long, short> T1; + constexpr P0 p0(2, 'a'); constexpr T1 t1 = p0; - static_assert(std::get<0>(t1) != std::get<0>(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'), ""); 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 index b7fa2e3a03cc5..4609b042556b9 100644 --- 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 @@ -20,6 +20,8 @@ #include <string> #include <cassert> +#include "test_macros.h" + struct Explicit { int value; explicit Explicit(int x) : value(x) {} @@ -43,7 +45,7 @@ struct D explicit D(int i) : B(i) {} }; -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 struct A { @@ -66,17 +68,17 @@ struct C int main() { { - typedef std::tuple<double> T0; - typedef std::tuple<int> T1; - T0 t0(2.5); + typedef std::tuple<long> T0; + typedef std::tuple<long long> T1; + T0 t0(2); T1 t1 = t0; assert(std::get<0>(t1) == 2); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { - typedef std::tuple<double> T0; + typedef std::tuple<int> T0; typedef std::tuple<A> T1; - constexpr T0 t0(2.5); + constexpr T0 t0(2); constexpr T1 t1 = t0; static_assert(std::get<0>(t1) == 2, ""); } @@ -89,17 +91,17 @@ int main() } #endif { - typedef std::tuple<double, char> T0; - typedef std::tuple<int, int> T1; - T0 t0(2.5, 'a'); + typedef std::tuple<long, char> T0; + typedef std::tuple<long long, int> T1; + T0 t0(2, '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)); + typedef std::tuple<long, char, D> T0; + typedef std::tuple<long long, int, B> T1; + T0 t0(2, 'a', D(3)); T1 t1 = t0; assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); @@ -107,9 +109,9 @@ int main() } { D d(3); - typedef std::tuple<double, char, D&> T0; - typedef std::tuple<int, int, B&> T1; - T0 t0(2.5, 'a', d); + typedef std::tuple<long, char, D&> T0; + typedef std::tuple<long long, int, B&> T1; + T0 t0(2, 'a', d); T1 t1 = t0; d.id_ = 2; assert(std::get<0>(t1) == 2); @@ -117,9 +119,9 @@ int main() 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); + typedef std::tuple<long, char, int> T0; + typedef std::tuple<long long, int, B> T1; + T0 t0(2, 'a', 3); T1 t1(t0); assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); 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 index 8423f5d0145fc..2af86fdd08687 100644 --- 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 @@ -48,24 +48,24 @@ struct D int main() { { - typedef std::tuple<double> T0; - typedef std::tuple<int> T1; - T0 t0(2.5); + typedef std::tuple<long> T0; + typedef std::tuple<long long> T1; + T0 t0(2); 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'); + typedef std::tuple<long, char> T0; + typedef std::tuple<long long, int> T1; + T0 t0(2, '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)); + typedef std::tuple<long, char, D> T0; + typedef std::tuple<long long, int, B> T1; + T0 t0(2, 'a', D(3)); T1 t1 = std::move(t0); assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); @@ -73,9 +73,9 @@ int main() } { D d(3); - typedef std::tuple<double, char, D&> T0; - typedef std::tuple<int, int, B&> T1; - T0 t0(2.5, 'a', d); + typedef std::tuple<long, char, D&> T0; + typedef std::tuple<long long, int, B&> T1; + T0 t0(2, 'a', d); T1 t1 = std::move(t0); d.id_ = 2; assert(std::get<0>(t1) == 2); @@ -83,9 +83,9 @@ int main() 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))); + typedef std::tuple<long, char, std::unique_ptr<D>> T0; + typedef std::tuple<long long, int, std::unique_ptr<B>> T1; + T0 t0(2, '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')); 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 index 783c9d1f06a8b..1137df2918dd0 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -19,6 +19,8 @@ #include <string> #include <cassert> +#include "test_macros.h" + struct Empty {}; int main() @@ -50,7 +52,7 @@ int main() assert(std::get<1>(t) == 'a'); assert(std::get<2>(t) == "some text"); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef std::tuple<int> T; constexpr T t0(2); diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp new file mode 100644 index 0000000000000..fbcda44e40654 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// ~tuple(); + +#include <tuple> +#include <string> +#include <cassert> +#include <type_traits> + +int main() +{ + static_assert(std::is_trivially_destructible< + std::tuple<> >::value, ""); + static_assert(std::is_trivially_destructible< + std::tuple<void*> >::value, ""); + static_assert(std::is_trivially_destructible< + std::tuple<int, float> >::value, ""); + static_assert(!std::is_trivially_destructible< + std::tuple<std::string> >::value, ""); + static_assert(!std::is_trivially_destructible< + std::tuple<int, std::string> >::value, ""); +} 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 index 0c93673532bb1..1cc13cf58ba8f 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp @@ -29,7 +29,7 @@ struct ConstructsWithTupleLeaf ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} template <class T> - ConstructsWithTupleLeaf(T t) { + ConstructsWithTupleLeaf(T) { static_assert(!std::is_same<T, T>::value, "Constructor instantiated for type other than int"); } 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 index 2dfbaff6cc1a7..13558f3fbe175 100644 --- 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 @@ -38,9 +38,9 @@ struct D 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))); + typedef std::pair<long, std::unique_ptr<D>> T0; + typedef std::tuple<long long, std::unique_ptr<B>> T1; + T0 t0(2, 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); |
