mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-21 23:30:38 +08:00
Implement LWG 2904.
Summary: - Removed the move-constructibe requirement from copy-assignable. - Updated `__assign_alt` such that we direct initialize if `_Tp` can be `nothrow`-constructible from `_Arg`, or `_Tp`'s move construction can throw. Otherwise, construct a temporary and move it. - Updated the tests to remove the pre-LWG2904 path. Depends on D32671. Reviewers: EricWF, CaseyCarter Reviewed By: EricWF Differential Revision: https://reviews.llvm.org/D33965 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@304891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -199,12 +199,8 @@ void test_T_assignment_performs_construction() {
|
||||
assert(false);
|
||||
} catch (...) { /* ... */
|
||||
}
|
||||
#ifdef _LIBCPP_VERSION // LWG2904
|
||||
assert(v.valueless_by_exception());
|
||||
#else // _LIBCPP_VERSION
|
||||
assert(v.index() == 0);
|
||||
assert(std::get<0>(v) == "hello");
|
||||
#endif // _LIBCPP_VERSION
|
||||
}
|
||||
{
|
||||
using V = std::variant<ThrowsAssignT, std::string>;
|
||||
@@ -213,28 +209,6 @@ void test_T_assignment_performs_construction() {
|
||||
assert(v.index() == 0);
|
||||
assert(std::get<0>(v).value == 42);
|
||||
}
|
||||
#ifdef _LIBCPP_VERSION // LWG2904
|
||||
{
|
||||
// Test that nothrow direct construction is preferred to nothrow move.
|
||||
using V = std::variant<MoveCrashes, std::string>;
|
||||
V v(std::in_place_type<std::string>, "hello");
|
||||
v = 42;
|
||||
assert(v.index() == 0);
|
||||
assert(std::get<0>(v).value == 42);
|
||||
}
|
||||
{
|
||||
// Test that throwing direct construction is preferred to copy-and-move when
|
||||
// move can throw.
|
||||
using V = std::variant<ThrowsCtorTandMove, std::string>;
|
||||
V v(std::in_place_type<std::string>, "hello");
|
||||
try {
|
||||
v = 42;
|
||||
assert(false);
|
||||
} catch(...) { /* ... */
|
||||
}
|
||||
assert(v.valueless_by_exception());
|
||||
}
|
||||
#endif // _LIBCPP_VERSION // LWG2904
|
||||
#endif // TEST_HAS_NO_EXCEPTIONS
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user