[libcxx-commits] [libcxx] 6ab3208 - Remove the unnecessary `is_nothrow_swappable` condition in `swap`.

Michael Park via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 8 10:47:10 PDT 2020


Author: Michael Park
Date: 2020-07-08T10:46:38-07:00
New Revision: 6ab3208d779ffb3b32744b0190d7035d4b369173

URL: https://github.com/llvm/llvm-project/commit/6ab3208d779ffb3b32744b0190d7035d4b369173
DIFF: https://github.com/llvm/llvm-project/commit/6ab3208d779ffb3b32744b0190d7035d4b369173.diff

LOG: Remove the unnecessary `is_nothrow_swappable` condition in `swap`.

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

Added: 
    

Modified: 
    libcxx/include/variant

Removed: 
    


################################################################################
diff  --git a/libcxx/include/variant b/libcxx/include/variant
index 502d8d83aeab..03557239a69e 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -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


        


More information about the libcxx-commits mailing list