[libcxx-commits] [PATCH] D83274: Remove the unnecessary `is_nothrow_swappable` condition in `swap`.

Michael Park via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 6 19:10:35 PDT 2020


mpark created this revision.
mpark added reviewers: ldionne, lewissbaker.
Herald added subscribers: libcxx-commits, dexonsmith.
Herald added a project: libc++.
Herald added a reviewer: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83274

Files:
  libcxx/include/variant


Index: libcxx/include/variant
===================================================================
--- libcxx/include/variant
+++ libcxx/include/variant
@@ -1063,8 +1063,7 @@
       }
       __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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83274.275887.patch
Type: text/x-patch
Size: 644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200707/e2550592/attachment.bin>


More information about the libcxx-commits mailing list