From 038bc9bfd6dfd94336e0bebf416f1bbc3ed3272e Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 23 Apr 2019 13:48:28 +0100 Subject: [PATCH] Implement correct std::variant triviality rules from P0602R4 The std::variant move assignment operator should not be trivial if the variant is not trivially move constructible. * include/std/variant (__detail::__variant::_Traits): Make _S_trivial_copy_assign depend on _S_trivial_copy_ctor and make _S_trivial_move_assign depend on _S_trivial_move_ctor, as per P0602R4. (__detail::__variant::_Copy_assign_alias): Only depend on _S_trivial_copy_assign, which subsumes _S_trivial_copy_ctor now. * testsuite/20_util/variant/compile.cc: Correct checks for trivial move assignment operators. From-SVN: r270510 --- libstdc++-v3/ChangeLog | 9 +++++++++ libstdc++-v3/include/std/variant | 13 +++++++------ libstdc++-v3/testsuite/20_util/variant/compile.cc | 14 +++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1d0192b66da..abfbfd8addb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2019-04-23 Jonathan Wakely + * include/std/variant (__detail::__variant::_Traits): Make + _S_trivial_copy_assign depend on _S_trivial_copy_ctor and make + _S_trivial_move_assign depend on _S_trivial_move_ctor, as per + P0602R4. + (__detail::__variant::_Copy_assign_alias): Only depend on + _S_trivial_copy_assign, which subsumes _S_trivial_copy_ctor now. + * testsuite/20_util/variant/compile.cc: Correct checks for trivial + move assignment operators. + PR libstdc++/90165 * include/std/variant (variant::__not_self): New helper for the is_same_v, variant>==false constraints. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index d65084eeb1f..0c9f8a39c5c 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -289,9 +289,11 @@ namespace __variant static constexpr bool _S_trivial_move_ctor = (is_trivially_move_constructible_v<_Types> && ...); static constexpr bool _S_trivial_copy_assign = - _S_trivial_dtor && (is_trivially_copy_assignable_v<_Types> && ...); + _S_trivial_dtor && _S_trivial_copy_ctor + && (is_trivially_copy_assignable_v<_Types> && ...); static constexpr bool _S_trivial_move_assign = - _S_trivial_dtor && (is_trivially_move_assignable_v<_Types> && ...); + _S_trivial_dtor && _S_trivial_move_ctor + && (is_trivially_move_assignable_v<_Types> && ...); // The following nothrow traits are for non-trivial SMFs. Trivial SMFs // are always nothrow. @@ -303,7 +305,8 @@ namespace __variant (is_nothrow_move_constructible_v<_Types> && ...); static constexpr bool _S_nothrow_copy_assign = false; static constexpr bool _S_nothrow_move_assign = - _S_nothrow_move_ctor && (is_nothrow_move_assignable_v<_Types> && ...); + _S_nothrow_move_ctor + && (is_nothrow_move_assignable_v<_Types> && ...); }; // Defines members and ctors. @@ -654,9 +657,7 @@ namespace __variant template using _Copy_assign_alias = - _Copy_assign_base<_Traits<_Types...>::_S_trivial_copy_assign - && _Traits<_Types...>::_S_trivial_copy_ctor, - _Types...>; + _Copy_assign_base<_Traits<_Types...>::_S_trivial_copy_assign, _Types...>; template struct _Move_assign_base : _Copy_assign_alias<_Types...> diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 6acf5bc627e..c6b18d08258 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -522,17 +522,17 @@ void test_triviality() TEST_TEMPLATE(=default, =default, =default, =default, , true, true, true, false) TEST_TEMPLATE(=default, =default, =default, , =default, true, true, false, true) TEST_TEMPLATE(=default, =default, =default, , , true, true, false, false) - TEST_TEMPLATE(=default, =default, , =default, =default, true, false, true, true) + TEST_TEMPLATE(=default, =default, , =default, =default, true, false, true, false) TEST_TEMPLATE(=default, =default, , =default, , true, false, true, false) - TEST_TEMPLATE(=default, =default, , , =default, true, false, false, true) + TEST_TEMPLATE(=default, =default, , , =default, true, false, false, false) TEST_TEMPLATE(=default, =default, , , , true, false, false, false) - TEST_TEMPLATE(=default, , =default, =default, =default, false, true, false, true) - TEST_TEMPLATE(=default, , =default, =default, , false, true, false, false) + TEST_TEMPLATE(=default, , =default, =default, =default, false, true, false, true) + TEST_TEMPLATE(=default, , =default, =default, , false, true, false, false) TEST_TEMPLATE(=default, , =default, , =default, false, true, false, true) TEST_TEMPLATE(=default, , =default, , , false, true, false, false) - TEST_TEMPLATE(=default, , , =default, =default, false, false, false, true) - TEST_TEMPLATE(=default, , , =default, , false, false, false, false) - TEST_TEMPLATE(=default, , , , =default, false, false, false, true) + TEST_TEMPLATE(=default, , , =default, =default, false, false, false, false) + TEST_TEMPLATE(=default, , , =default, , false, false, false, false) + TEST_TEMPLATE(=default, , , , =default, false, false, false, false) TEST_TEMPLATE(=default, , , , , false, false, false, false) TEST_TEMPLATE( , =default, =default, =default, =default, false, false, false, false) TEST_TEMPLATE( , =default, =default, =default, , false, false, false, false) -- 2.30.2