Skip to content

Commit

Permalink
Remove the unnecessary is_nothrow_swappable condition in swap.
Browse files Browse the repository at this point in the history
Thanks to @lewissbaker who pointed out the unnecessary condition in
https://reviews.llvm.org/D81954#inline-756872. Since this codepath does not
make use of `swap` anyway (that codepath is a different branch), we can safely
remove this condition and produce better codegen when all types are nothrow
movable but are potentially-throwing swappable.

See codegen in https://gcc.godbolt.org/z/uDFZjz

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D83274
  • Loading branch information
mpark committed Jul 8, 2020
1 parent 82206e7 commit 6ab3208
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions libcxx/include/variant
Expand Up @@ -1063,8 +1063,7 @@ public:
}
__impl __tmp(_VSTD::move(*__rhs));
#ifndef _LIBCPP_NO_EXCEPTIONS
if constexpr (__all<(is_nothrow_move_constructible_v<_Types> &&
is_nothrow_swappable_v<_Types>)...>::value) {
if constexpr (__all<is_nothrow_move_constructible_v<_Types>...>::value) {
this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
} else {
// EXTENSION: When the move construction of `__lhs` into `__rhs` throws
Expand Down

0 comments on commit 6ab3208

Please sign in to comment.