From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 2FC423953D14 for ; Thu, 8 Apr 2021 16:50:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2FC423953D14 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-5hMv24u7OAGhrl4iZnVyPw-1; Thu, 08 Apr 2021 12:50:20 -0400 X-MC-Unique: 5hMv24u7OAGhrl4iZnVyPw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC8878030DB; Thu, 8 Apr 2021 16:50:19 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 852D85C1C4; Thu, 8 Apr 2021 16:50:19 +0000 (UTC) Date: Thu, 8 Apr 2021 17:50:18 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify noexcept-specifiers for move constructors Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="oN7SoD1N3IFc9y9m" Content-Disposition: inline X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Apr 2021 16:50:25 -0000 --oN7SoD1N3IFc9y9m Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This puts the logic for the noexcept-specifier in one place, and then reuses it elsewhere. This means checking whether the move constructor can throw doesn't need to do overload resolution and then check whether some other constructor can throw, we just get the answer directly. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (_Hashtable::_S_nothrow_move()): New function to determine noexcept-specifier for move constructors. (_Hashtable): Use _S_nothrow_move() on move constructors. * testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc: Correct static assertion message. * testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc: Likewise. * testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc: Likewise. * testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc: Likewise. Tested powerpc64le-linux. Committed to trunk. --oN7SoD1N3IFc9y9m Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 1cbba49e3417d9b0661e70301d6fb7a7f52fd360 Author: Jonathan Wakely Date: Thu Apr 8 16:29:11 2021 libstdc++: Simplify noexcept-specifiers for move constructors This puts the logic for the noexcept-specifier in one place, and then reuses it elsewhere. This means checking whether the move constructor can throw doesn't need to do overload resolution and then check whether some other constructor can throw, we just get the answer directly. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (_Hashtable::_S_nothrow_move()): New function to determine noexcept-specifier for move constructors. (_Hashtable): Use _S_nothrow_move() on move constructors. * testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc: Correct static assertion message. * testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc: Likewise. * testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc: Likewise. * testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc: Likewise. diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index fa80675ad91..39872ce5342 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -472,10 +472,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __hashtable_alloc(__node_alloc_type(__a)) { } + template + static constexpr bool + _S_nothrow_move() + { + if _GLIBCXX17_CONSTEXPR (_No_realloc) + if _GLIBCXX17_CONSTEXPR (is_nothrow_copy_constructible<_Hash>()) + return is_nothrow_copy_constructible<_Equal>(); + return false; + } + _Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a, true_type /* alloc always equal */) - noexcept(std::is_nothrow_copy_constructible<_Hash>::value && - std::is_nothrow_copy_constructible<_Equal>::value); + noexcept(_S_nothrow_move()); _Hashtable(_Hashtable&&, __node_alloc_type&&, false_type /* alloc always equal */); @@ -508,19 +517,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Use delegating constructors. _Hashtable(_Hashtable&& __ht) - noexcept( noexcept( - _Hashtable(std::declval<_Hashtable>(), - std::declval<__node_alloc_type>(), - true_type{})) ) + noexcept(_S_nothrow_move()) : _Hashtable(std::move(__ht), std::move(__ht._M_node_allocator()), true_type{}) { } _Hashtable(_Hashtable&& __ht, const allocator_type& __a) - noexcept( noexcept( - _Hashtable(std::declval<_Hashtable>(), - std::declval<__node_alloc_type>(), - typename __node_alloc_traits::is_always_equal{})) ) + noexcept(_S_nothrow_move<__node_alloc_traits::_S_always_equal()>()) : _Hashtable(std::move(__ht), __node_alloc_type(__a), typename __node_alloc_traits::is_always_equal{}) { } @@ -1400,8 +1403,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>:: _Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a, true_type /* alloc always equal */) - noexcept(std::is_nothrow_copy_constructible<_Hash>::value && - std::is_nothrow_copy_constructible<_Equal>::value) + noexcept(_S_nothrow_move()) : __hashtable_base(__ht), __map_base(__ht), __rehash_base(__ht), diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc index 96245aa4c88..015646adf23 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc @@ -40,7 +40,7 @@ struct not_noexcept_copy_cons_hash using type2 = std::unordered_map; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); @@ -59,7 +59,7 @@ using type3 = std::unordered_map, not_noexcept_copy_cons_equal_to>; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc index efc8d337e7e..1e0b1059d7d 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc @@ -40,7 +40,7 @@ struct not_noexcept_copy_cons_hash using type2 = std::unordered_multimap; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); @@ -59,7 +59,7 @@ using type3 = std::unordered_multimap, not_noexcept_copy_cons_equal_to>; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc index cc2a8e31051..3e603802f13 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc @@ -40,7 +40,7 @@ struct not_noexcept_copy_cons_hash using type2 = std::unordered_multiset; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); @@ -59,7 +59,7 @@ using type3 = std::unordered_multiset, not_noexcept_copy_cons_equal_to>; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc index f68095302d5..28cb539e9f5 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc @@ -40,7 +40,7 @@ struct not_noexcept_copy_cons_hash using type2 = std::unordered_set; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); @@ -59,7 +59,7 @@ using type3 = std::unordered_set, not_noexcept_copy_cons_equal_to>; static_assert( !std::is_nothrow_move_constructible::value, - "noexcept move constructor" ); + "not noexcept move constructor" ); static_assert( !std::is_nothrow_constructible::value, "not noexcept move constructor with allocator" ); --oN7SoD1N3IFc9y9m--