Index: libcxx/trunk/include/variant =================================================================== --- libcxx/trunk/include/variant +++ libcxx/trunk/include/variant @@ -358,7 +358,6 @@ static constexpr _Trait __copy_assignable_trait = __common_trait( {__copy_constructible_trait, - __move_constructible_trait, __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...}); static constexpr _Trait __move_assignable_trait = __common_trait( @@ -877,25 +876,24 @@ } protected: - template + template inline _LIBCPP_INLINE_VISIBILITY - void __assign_alt(__alt<_Ip, _Tp>& __a, - _Arg&& __arg, - bool_constant<_CopyAssign> __tag) { + void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg) { if (this->index() == _Ip) { __a.__value = _VSTD::forward<_Arg>(__arg); } else { struct { void operator()(true_type) const { - __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg))); + __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg)); } void operator()(false_type) const { - __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg)); + __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg))); } __assignment* __this; _Arg&& __arg; } __impl{this, _VSTD::forward<_Arg>(__arg)}; - __impl(__tag); + __impl(bool_constant || + !is_nothrow_move_constructible_v<_Tp>>{}); } } @@ -912,8 +910,7 @@ [this](auto& __this_alt, auto&& __that_alt) { this->__assign_alt( __this_alt, - _VSTD::forward(__that_alt).__value, - is_lvalue_reference<_That>{}); + _VSTD::forward(__that_alt).__value); }, *this, _VSTD::forward<_That>(__that)); } @@ -1013,8 +1010,7 @@ inline _LIBCPP_INLINE_VISIBILITY void __assign(_Arg&& __arg) { this->__assign_alt(__access::__base::__get_alt<_Ip>(*this), - _VSTD::forward<_Arg>(__arg), - false_type{}); + _VSTD::forward<_Arg>(__arg)); } inline _LIBCPP_INLINE_VISIBILITY @@ -1088,7 +1084,6 @@ __all...>::value>, private __sfinae_assign_base< __all<(is_copy_constructible_v<_Types> && - is_move_constructible_v<_Types> && is_copy_assignable_v<_Types>)...>::value, __all<(is_move_constructible_v<_Types> && is_move_assignable_v<_Types>)...>::value> { Index: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp =================================================================== --- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp +++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp @@ -199,12 +199,8 @@ 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; @@ -213,28 +209,6 @@ 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; - V v(std::in_place_type, "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; - V v(std::in_place_type, "hello"); - try { - v = 42; - assert(false); - } catch(...) { /* ... */ - } - assert(v.valueless_by_exception()); - } -#endif // _LIBCPP_VERSION // LWG2904 #endif // TEST_HAS_NO_EXCEPTIONS } Index: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp =================================================================== --- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp +++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp @@ -224,13 +224,7 @@ } { using V = std::variant; -#ifdef _LIBCPP_VERSION // LWG2904 - // variant only provides copy assignment when both the copy and move - // constructors are well formed - static_assert(!std::is_copy_assignable::value, ""); -#else // _LIBCPP_VERSION // LWG2904 static_assert(std::is_copy_assignable::value, ""); -#endif // _LIBCPP_VERSION // LWG2904 } { using V = std::variant; @@ -263,12 +257,10 @@ using V = std::variant; static_assert(std::is_trivially_copy_assignable::value, ""); } -#ifndef _LIBCPP_VERSION // LWG2904 { using V = std::variant; static_assert(std::is_trivially_copy_assignable::value, ""); } -#endif // _LIBCPP_VERSION } void test_copy_assignment_empty_empty() { @@ -487,41 +479,21 @@ assert(false); } catch (...) { /* ... */ } -#ifdef _LIBCPP_VERSION // LWG2904 - // Test that if copy construction throws then original value is unchanged. - assert(v1.index() == 2); - assert(std::get<2>(v1) == "hello"); -#else // _LIBCPP_VERSION // LWG2904 // Test that copy construction is used directly if move construction may throw, // resulting in a valueless variant if copy throws. assert(v1.valueless_by_exception()); -#endif // _LIBCPP_VERSION // LWG2904 } { using V = std::variant; V v1(std::in_place_type, "hello"); V v2(std::in_place_type); assert(MoveThrows::alive == 1); -#ifdef _LIBCPP_VERSION // LWG2904 - // Test that if move construction throws then the variant is left - // valueless by exception. - try { - v1 = v2; - assert(false); - } catch (...) { /* ... */ - } - assert(v1.valueless_by_exception()); - assert(v2.index() == 1); - assert(MoveThrows::alive == 1); -#else // _LIBCPP_VERSION // LWG2904 // Test that copy construction is used directly if move construction may throw. v1 = v2; assert(v1.index() == 1); assert(v2.index() == 1); assert(MoveThrows::alive == 2); -#endif // _LIBCPP_VERSION // LWG2904 } -#ifndef _LIBCPP_VERSION // LWG2904 { // Test that direct copy construction is preferred when it cannot throw. using V = std::variant; @@ -533,7 +505,6 @@ assert(v2.index() == 1); assert(CopyCannotThrow::alive == 2); } -#endif // _LIBCPP_VERSION // LWG2904 { using V = std::variant; V v1(std::in_place_type); Index: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp =================================================================== --- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp +++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp @@ -183,13 +183,7 @@ } { using V = std::variant; -#ifdef _LIBCPP_VERSION // LWG2904 - // variant only provides move assignment when both the move constructor - // and move assignment operator are well formed. - static_assert(!std::is_move_assignable::value, ""); -#else // _LIBCPP_VERSION // LWG2904 static_assert(std::is_move_assignable::value, ""); -#endif // _LIBCPP_VERSION // LWG2904 } { using V = std::variant; @@ -232,12 +226,10 @@ using V = std::variant; static_assert(!std::is_trivially_move_assignable::value, ""); } -#ifndef _LIBCPP_VERSION // LWG2904 { using V = std::variant; static_assert(std::is_trivially_move_assignable::value, ""); } -#endif // _LIBCPP_VERSION // LWG2904 } void test_move_assignment_empty_empty() {