From f2215ae626a02c74abb2982630d85180886d7eda Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Tue, 18 Nov 2014 23:01:57 +0000 Subject: [PATCH] Flush out test cases for tuples constructor SFINAE git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@222278 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../tuple.tuple/tuple.cnstr/UTypes.pass.cpp | 74 +++++++++++++++-- .../tuple.cnstr/alloc_UTypes.pass.cpp | 81 +++++++++++++++---- 2 files changed, 132 insertions(+), 23 deletions(-) diff --git a/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp index 7359d77c..3d8b194e 100644 --- a/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp +++ b/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -33,6 +33,69 @@ struct A 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() { { @@ -66,14 +129,6 @@ int main() assert(std::get<1>(t) == MoveOnly()); assert(std::get<2>(t) == MoveOnly()); } - { - // 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. - static_assert(!std::is_constructible, MoveOnly>(), ""); - static_assert(!std::is_constructible, MoveOnly, MoveOnly>(), ""); - } #if _LIBCPP_STD_VER > 11 { constexpr std::tuple t0{Empty()}; @@ -83,4 +138,7 @@ int main() 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp index 97469869..00bc5e05 100644 --- a/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp +++ b/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -24,6 +24,69 @@ 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() { { @@ -70,19 +133,7 @@ int main() assert(std::get<1>(t) == MoveOnly()); assert(std::get<2>(t) == MoveOnly()); } - { - // 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. - static_assert(!std::is_constructible< - std::tuple, - std::allocator_arg_t, A1, MoveOnly - >::value, ""); - - static_assert(!std::is_constructible< - std::tuple, - std::allocator_arg_t, A1, MoveOnly, MoveOnly - >::value, ""); - } + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); }