Test changes for P0504R0 "Revisiting in-place tag types for any/optional/variant". Patch from Casey Carter

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@287249 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-11-17 19:23:35 +00:00
parent e6479bc783
commit 77dabb302b
5 changed files with 54 additions and 86 deletions

View File

@@ -40,7 +40,7 @@ void test_in_place_type() {
assert(Type::count == 0);
Type::reset();
{
any a(std::in_place<Type>);
any a(std::in_place_type<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<Type&>);
any a(std::in_place_type<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<Type>, 101);
any a(std::in_place_type<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<Type>, -1, 42, -1);
any a(std::in_place_type<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<Type>()); ((void)g);
{
any a(std::in_place<Type>);
any a(std::in_place_type<Type>);
assertArgsMatch<Type>(a);
}
{
any a(std::in_place<Type>, -1, 42, -1);
any a(std::in_place_type<Type>, -1, 42, -1);
assertArgsMatch<Type, int, int, int>(a);
}
// initializer_list constructor tests
{
any a(std::in_place<Type>, {-1, 42, -1});
any a(std::in_place_type<Type>, {-1, 42, -1});
assertArgsMatch<Type, std::initializer_list<int>>(a);
}
{
int x = 42;
any a(std::in_place<Type&>, {-1, 42, -1}, x);
any a(std::in_place_type<Type&>, {-1, 42, -1}, x);
assertArgsMatch<Type, std::initializer_list<int>, 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<Type>, test_func);
any a(std::in_place_type<Type>, test_func);
assert(containsType<DecayT>(a));
assert(any_cast<DecayT>(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<Type>, my_arr);
any a(std::in_place_type<Type>, my_arr);
assert(containsType<DecayT>(a));
assert(any_cast<DecayT>(a) == my_arr);
}
{
using Type = int[5];
using DecayT = int*;
any a(std::in_place<Type>);
any a(std::in_place_type<Type>);
assert(containsType<DecayT>(a));
assert(any_cast<DecayT>(a) == nullptr);
}

View File

@@ -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<int>;
using OKTag = std::in_place_t;
using OKDecay = std::decay_t<OKTag>;
// Test that the tag type is properly handled in SFINAE
BadTag t = std::in_place;
BadTag t = std::in_place_type<int>;
OKTag ot = std::in_place;
{
std::any a(t);
@@ -124,12 +123,7 @@ void test_sfinae_constraints() {
}
{
std::any a(ot);
assertContains<OKDecay>(a, ot);
}
{
OKDecay d = ot;
std::any a(d);
assertContains<OKDecay>(a, ot);
assert(containsType<OKTag>(a));
}
{
struct Dummy { Dummy() = delete; };

View File

@@ -39,7 +39,7 @@ void test_emplace_type() {
assert(Type::count == 0);
Type::reset();
{
any a(std::in_place<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>();
@@ -53,7 +53,7 @@ void test_emplace_type() {
assert(Type::count == 0);
Type::reset();
{
any a(std::in_place<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>(101);
@@ -67,7 +67,7 @@ void test_emplace_type() {
assert(Type::count == 0);
Type::reset();
{
any a(std::in_place<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>(-1, 42, -1);
@@ -87,14 +87,14 @@ void test_emplace_type_tracked() {
// constructing from a small type should perform no allocations.
DisableAllocationGuard g(isSmallType<Type>()); ((void)g);
{
any a(std::in_place<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>();
assert(Tracked::count == 0);
assertArgsMatch<Type>(a);
}
{
any a(std::in_place<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>(-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<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>({-1, 42, -1});
assert(Tracked::count == 0);
@@ -110,7 +110,7 @@ void test_emplace_type_tracked() {
}
{
int x = 42;
any a(std::in_place<Tracked>);
any a(std::in_place_type<Tracked>);
assert(Tracked::count == 1);
a.emplace<Type>({-1, 42, -1}, x);
assert(Tracked::count == 0);

View File

@@ -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);