diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /libcxx/include/variant | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'libcxx/include/variant')
-rw-r--r-- | libcxx/include/variant | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/libcxx/include/variant b/libcxx/include/variant index 98a62c992fa1..03557239a69e 100644 --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -1063,18 +1063,24 @@ public: } __impl __tmp(_VSTD::move(*__rhs)); #ifndef _LIBCPP_NO_EXCEPTIONS - // EXTENSION: When the move construction of `__lhs` into `__rhs` throws - // and `__tmp` is nothrow move constructible then we move `__tmp` back - // into `__rhs` and provide the strong exception safety guarantee. - try { + if constexpr (__all<is_nothrow_move_constructible_v<_Types>...>::value) { this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); - } catch (...) { - if (__tmp.__move_nothrow()) { - this->__generic_construct(*__rhs, _VSTD::move(__tmp)); + } else { + // EXTENSION: When the move construction of `__lhs` into `__rhs` throws + // and `__tmp` is nothrow move constructible then we move `__tmp` back + // into `__rhs` and provide the strong exception safety guarantee. + try { + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); + } catch (...) { + if (__tmp.__move_nothrow()) { + this->__generic_construct(*__rhs, _VSTD::move(__tmp)); + } + throw; } - throw; } #else + // this isn't consolidated with the `if constexpr` branch above due to + // `throw` being ill-formed with exceptions disabled even when discarded. this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); #endif this->__generic_construct(*__lhs, _VSTD::move(__tmp)); |