[libcxx] Reorganize tests since the application of P0602R4
Summary: P0602R4 makes the special member functions of optional and variant conditionally trivial based on the types in the optional/variant. We already implemented that, but the tests were organized as if this were a non-standard extension. This patch reorganizes the tests in a way that makes more sense since this is not an extension anymore. Reviewers: EricWF, mpark, mclow.lists Subscribers: christof, jkorous, dexonsmith, libcxx-commits Differential Revision: https://reviews.llvm.org/D54772 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@350884 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,11 +12,12 @@
|
||||
|
||||
// optional<T>& operator=(optional<T>&& rhs)
|
||||
// noexcept(is_nothrow_move_assignable<T>::value &&
|
||||
// is_nothrow_move_constructible<T>::value);
|
||||
// is_nothrow_move_constructible<T>::value); // constexpr in C++20
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "archetypes.hpp"
|
||||
@@ -51,6 +52,21 @@ struct Y {};
|
||||
bool X::throw_now = false;
|
||||
int X::alive = 0;
|
||||
|
||||
|
||||
template <class Tp>
|
||||
constexpr bool assign_empty(optional<Tp>&& lhs) {
|
||||
optional<Tp> rhs;
|
||||
lhs = std::move(rhs);
|
||||
return !lhs.has_value() && !rhs.has_value();
|
||||
}
|
||||
|
||||
template <class Tp>
|
||||
constexpr bool assign_value(optional<Tp>&& lhs) {
|
||||
optional<Tp> rhs(101);
|
||||
lhs = std::move(rhs);
|
||||
return lhs.has_value() && rhs.has_value() && *lhs == Tp{101};
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -97,6 +113,24 @@ int main()
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
using O = optional<int>;
|
||||
#if TEST_STD_VER > 17
|
||||
LIBCPP_STATIC_ASSERT(assign_empty(O{42}), "");
|
||||
LIBCPP_STATIC_ASSERT(assign_value(O{42}), "");
|
||||
#endif
|
||||
assert(assign_empty(O{42}));
|
||||
assert(assign_value(O{42}));
|
||||
}
|
||||
{
|
||||
using O = optional<TrivialTestTypes::TestType>;
|
||||
#if TEST_STD_VER > 17
|
||||
LIBCPP_STATIC_ASSERT(assign_empty(O{42}), "");
|
||||
LIBCPP_STATIC_ASSERT(assign_value(O{42}), "");
|
||||
#endif
|
||||
assert(assign_empty(O{42}));
|
||||
assert(assign_value(O{42}));
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{
|
||||
static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, "");
|
||||
|
||||
Reference in New Issue
Block a user