From: Eric Fiselier Date: Thu, 17 Nov 2016 19:23:35 +0000 (+0000) Subject: Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant... X-Git-Tag: llvmorg-4.0.0-rc1~4281 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66ddd34e8db137234cdf5924c88f148033da5557;p=platform%2Fupstream%2Fllvm.git Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant". Patch from Casey Carter llvm-svn: 287249 --- diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp index 98b8c87..4cf5d91 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp @@ -40,7 +40,7 @@ void test_in_place_type() { assert(Type::count == 0); Type::reset(); { - any a(std::in_place); + any a(std::in_place_type); assert(Type::count == 1); assert(Type::copied == 0); @@ -50,7 +50,7 @@ void test_in_place_type() { assert(Type::count == 0); Type::reset(); { // Test that the in_place argument is properly decayed - any a(std::in_place); + any a(std::in_place_type); assert(Type::count == 1); assert(Type::copied == 0); @@ -60,7 +60,7 @@ void test_in_place_type() { assert(Type::count == 0); Type::reset(); { - any a(std::in_place, 101); + any a(std::in_place_type, 101); assert(Type::count == 1); assert(Type::copied == 0); @@ -70,7 +70,7 @@ void test_in_place_type() { assert(Type::count == 0); Type::reset(); { - any a(std::in_place, -1, 42, -1); + any a(std::in_place_type, -1, 42, -1); assert(Type::count == 1); assert(Type::copied == 0); @@ -86,21 +86,21 @@ void test_in_place_type_tracked() { // constructing from a small type should perform no allocations. DisableAllocationGuard g(isSmallType()); ((void)g); { - any a(std::in_place); + any a(std::in_place_type); assertArgsMatch(a); } { - any a(std::in_place, -1, 42, -1); + any a(std::in_place_type, -1, 42, -1); assertArgsMatch(a); } // initializer_list constructor tests { - any a(std::in_place, {-1, 42, -1}); + any a(std::in_place_type, {-1, 42, -1}); assertArgsMatch>(a); } { int x = 42; - any a(std::in_place, {-1, 42, -1}, x); + any a(std::in_place_type, {-1, 42, -1}, x); assertArgsMatch, int&>(a); } } @@ -111,7 +111,7 @@ void test_in_place_type_decayed() { { using Type = decltype(test_func); using DecayT = void(*)(); - any a(std::in_place, test_func); + any a(std::in_place_type, test_func); assert(containsType(a)); assert(any_cast(a) == test_func); } @@ -119,14 +119,14 @@ void test_in_place_type_decayed() { int my_arr[5]; using Type = int(&)[5]; using DecayT = int*; - any a(std::in_place, my_arr); + any a(std::in_place_type, my_arr); assert(containsType(a)); assert(any_cast(a) == my_arr); } { using Type = int[5]; using DecayT = int*; - any a(std::in_place); + any a(std::in_place_type); assert(containsType(a)); assert(any_cast(a) == nullptr); } diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp index 8795dfd..a164fbe 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp @@ -106,13 +106,12 @@ void test_copy_move_value() { } } -// Test that any(ValueType&&) is *never* selected for a std::in_place type. +// Test that any(ValueType&&) is *never* selected for a std::in_place_type_t specialization. void test_sfinae_constraints() { using BadTag = std::in_place_type_t; using OKTag = std::in_place_t; - using OKDecay = std::decay_t; // Test that the tag type is properly handled in SFINAE - BadTag t = std::in_place; + BadTag t = std::in_place_type; OKTag ot = std::in_place; { std::any a(t); @@ -124,12 +123,7 @@ void test_sfinae_constraints() { } { std::any a(ot); - assertContains(a, ot); - } - { - OKDecay d = ot; - std::any a(d); - assertContains(a, ot); + assert(containsType(a)); } { struct Dummy { Dummy() = delete; }; diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp index 2afb41e..65d94fd 100644 --- a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp @@ -39,7 +39,7 @@ void test_emplace_type() { assert(Type::count == 0); Type::reset(); { - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace(); @@ -53,7 +53,7 @@ void test_emplace_type() { assert(Type::count == 0); Type::reset(); { - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace(101); @@ -67,7 +67,7 @@ void test_emplace_type() { assert(Type::count == 0); Type::reset(); { - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace(-1, 42, -1); @@ -87,14 +87,14 @@ void test_emplace_type_tracked() { // constructing from a small type should perform no allocations. DisableAllocationGuard g(isSmallType()); ((void)g); { - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace(); assert(Tracked::count == 0); assertArgsMatch(a); } { - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace(-1, 42, -1); assert(Tracked::count == 0); @@ -102,7 +102,7 @@ void test_emplace_type_tracked() { } // initializer_list constructor tests { - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace({-1, 42, -1}); assert(Tracked::count == 0); @@ -110,7 +110,7 @@ void test_emplace_type_tracked() { } { int x = 42; - any a(std::in_place); + any a(std::in_place_type); assert(Tracked::count == 1); a.emplace({-1, 42, -1}, x); assert(Tracked::count == 0); diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp index 0b49cee..eb31a20 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp @@ -192,7 +192,6 @@ void test_cast_to_value() { Type::reset(); { any a((Type(42))); - any const& ca = a; assert(Type::count == 1); assert(Type::copied == 0); assert(Type::moved == 1); diff --git a/libcxx/test/std/utilities/utility/utility.inplace/inplace.pass.cpp b/libcxx/test/std/utilities/utility/utility.inplace/inplace.pass.cpp index 0cf8e38..e87c6f3 100644 --- a/libcxx/test/std/utilities/utility/utility.inplace/inplace.pass.cpp +++ b/libcxx/test/std/utilities/utility/utility.inplace/inplace.pass.cpp @@ -11,21 +11,24 @@ // -// struct in_place_tag { in_place_tag() = delete; }; -// -// using in_place_t = in_place_tag(&)(unspecified); +// struct in_place_t { +// explicit in_place_t() = default; +// }; +// inline constexpr in_place_t in_place{}; + // template -// using in_place_type_t = in_place_tag(&)(unspecified); -// template -// using in_place_index_t = in_place_tag(&)(unspecified); -// -// in_place_tag in_place(unspecified); -// -// template ; -// in_place_tag in_place(unspecified); -// -// template -// in_place_tag in_place(unspecified); +// struct in_place_type_t { +// explicit in_place_type_t() = default; +// }; +// template +// inline constexpr in_place_type_t in_place_type{}; + +// template +// struct in_place_index_t { +// explicit in_place_index_t() = default; +// }; +// template +// inline constexpr in_place_index_t in_place_index{}; #include #include @@ -34,66 +37,38 @@ #include "test_macros.h" #include "type_id.h" -template -struct CheckRet : std::false_type {}; -template -struct CheckRet : std::true_type {}; - -TypeID const* test_fn(std::in_place_t) { return &makeTypeID(); } -template -TypeID const* test_fn(std::in_place_type_t) -{ return &makeTypeID>(); } - -template -TypeID const* test_fn(std::in_place_index_t) -{ return &makeTypeID>(); } - -// Concrete test overloads that don't have to be deduced. -template -TypeID const* concrete_test_fn(Tag) { return &makeTypeID(); } - -template -bool check_tag_basic() { - using RawTp = typename std::remove_reference::type; - static_assert(std::is_lvalue_reference::value, ""); - static_assert(std::is_function::value, ""); - static_assert(CheckRet::value, ""); - auto concrete_fn = concrete_test_fn; - return test_fn((Tp)std::in_place) == &makeTypeID() - && concrete_fn(std::in_place) == &makeTypeID(); +template +constexpr bool check_tag(Up) { + return std::is_same>::value + && std::is_same::value; } int main() { - // test in_place_tag - { - static_assert(!std::is_default_constructible::value, ""); - } // test in_place_t { using T = std::in_place_t; - assert(check_tag_basic()); - assert(test_fn((T)std::in_place) == &makeTypeID()); + static_assert(check_tag(std::in_place)); } // test in_place_type_t { using T1 = std::in_place_type_t; using T2 = std::in_place_type_t; using T3 = std::in_place_type_t; - assert(check_tag_basic()); - assert(check_tag_basic()); - assert(check_tag_basic()); - static_assert(!std::is_same::value && !std::is_same::value, ""); - static_assert(!std::is_same::value, ""); + static_assert(!std::is_same::value && !std::is_same::value); + static_assert(!std::is_same::value); + static_assert(check_tag(std::in_place_type)); + static_assert(check_tag(std::in_place_type)); + static_assert(check_tag(std::in_place_type)); } // test in_place_index_t { using T1 = std::in_place_index_t<0>; using T2 = std::in_place_index_t<1>; using T3 = std::in_place_index_t(-1)>; - assert(check_tag_basic()); - assert(check_tag_basic()); - assert(check_tag_basic()); - static_assert(!std::is_same::value && !std::is_same::value, ""); - static_assert(!std::is_same::value, ""); + static_assert(!std::is_same::value && !std::is_same::value); + static_assert(!std::is_same::value); + static_assert(check_tag(std::in_place_index<0>)); + static_assert(check_tag(std::in_place_index<1>)); + static_assert(check_tag(std::in_place_index(-1)>)); } -} \ No newline at end of file +}