From patchwork Thu Sep 1 15:51:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 112941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 1AE7BB6F8E for ; Fri, 2 Sep 2011 01:51:49 +1000 (EST) Received: (qmail 31237 invoked by alias); 1 Sep 2011 15:51:45 -0000 Received: (qmail 31219 invoked by uid 22791); 1 Sep 2011 15:51:43 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Sep 2011 15:51:27 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p81FpO95017478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 1 Sep 2011 15:51:25 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p81FpN35001357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Sep 2011 15:51:23 GMT Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p81FpHNi002912; Thu, 1 Sep 2011 10:51:18 -0500 Received: from [192.168.1.4] (/79.52.212.161) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Sep 2011 08:51:17 -0700 Message-ID: <4E5FA9F4.50402@oracle.com> Date: Thu, 01 Sep 2011 17:51:16 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Remove noexcept mistakenly added to the unordered_* move cons X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, while working on libstdc++/50257 I noticed this recent mistake of mine: given our current impl of the unordered containers, the move constructor allocates memory, thus can certainly throw, similarly to deque, for example. Also, I reordered the operations in the body of the move constructor, because we weren't updating __ht._M_rehash_policy before using _M_next_bkt on it. Tested x86_64-linux, committed to mainline (the issue with the body of the move cons exists also in 4.6.x, should be fixed there too, probably) Thanks, Paolo. //////////////////// 2011-09-01 Paolo Carlini * include/bits/hashtable.h (_Hashtable<>::_Hashtable(_Hashtable&&)): Remove noexcept, the move constructor allocates memory; rearrange the code in the body to consistently update __ht._M_rehash_policy before using _M_next_bkt on it. * include/debug/unordered_map: Adjust. * include/debug/unordered_set: Likewise. * include/profile/unordered_map: Likewise. * include/profile/unordered_set: Likewise. * testsuite/23_containers/unordered_map/cons/ noexcept_move_construct.cc: Remove. * testsuite/23_containers/unordered_set/cons/ noexcept_move_construct.cc: Likewise. * testsuite/23_containers/unordered_multimap/cons/ noexcept_move_construct.cc: Likewise. * testsuite/23_containers/unordered_multiset/cons/ noexcept_move_construct.cc: Likewise. Index: include/debug/unordered_map =================================================================== --- include/debug/unordered_map (revision 178397) +++ include/debug/unordered_map (working copy) @@ -104,8 +104,6 @@ : _Base(__x) { } unordered_map(unordered_map&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { } unordered_map(initializer_list __l, @@ -485,8 +483,6 @@ : _Base(__x) { } unordered_multimap(unordered_multimap&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { } unordered_multimap(initializer_list __l, Index: include/debug/unordered_set =================================================================== --- include/debug/unordered_set (revision 178397) +++ include/debug/unordered_set (working copy) @@ -104,8 +104,6 @@ : _Base(__x) { } unordered_set(unordered_set&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { } unordered_set(initializer_list __l, @@ -480,8 +478,6 @@ : _Base(__x) { } unordered_multiset(unordered_multiset&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { } unordered_multiset(initializer_list __l, Index: include/profile/unordered_map =================================================================== --- include/profile/unordered_map (revision 178397) +++ include/profile/unordered_map (working copy) @@ -104,8 +104,6 @@ } unordered_map(unordered_map&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -374,8 +372,6 @@ } unordered_multimap(unordered_multimap&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { __profcxx_hashtable_construct(this, _Base::bucket_count()); Index: include/profile/unordered_set =================================================================== --- include/profile/unordered_set (revision 178397) +++ include/profile/unordered_set (working copy) @@ -103,8 +103,6 @@ } unordered_set(unordered_set&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -348,8 +346,6 @@ } unordered_multiset(unordered_multiset&& __x) - noexcept(__and_, - is_nothrow_copy_constructible<_Pred>>::value) : _Base(std::move(__x)) { __profcxx_hashtable_construct(this, _Base::bucket_count()); Index: include/bits/hashtable.h =================================================================== --- include/bits/hashtable.h (revision 178397) +++ include/bits/hashtable.h (working copy) @@ -674,8 +674,6 @@ _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: _Hashtable(_Hashtable&& __ht) - noexcept(__and_, - is_nothrow_copy_constructible<_H1>>::value) : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht), __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, __chc>(__ht), @@ -687,12 +685,11 @@ _M_element_count(__ht._M_element_count), _M_rehash_policy(__ht._M_rehash_policy) { - size_type __n_bkt = __ht._M_rehash_policy._M_next_bkt(0); - __ht._M_buckets = __ht._M_allocate_buckets(__n_bkt); - __ht._M_bucket_count = __n_bkt; + __ht._M_rehash_policy = _RehashPolicy(); + __ht._M_bucket_count = __ht._M_rehash_policy._M_next_bkt(0); + __ht._M_buckets = __ht._M_allocate_buckets(__ht._M_bucket_count); __ht._M_begin_bucket_index = __ht._M_bucket_count; __ht._M_element_count = 0; - __ht._M_rehash_policy = _RehashPolicy(); } template -// -// Copyright (C) 2011 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include - -typedef std::unordered_map umtype; - -static_assert(std::is_nothrow_move_constructible::value, "Error"); Index: testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc =================================================================== --- testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc (revision 178397) +++ testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc (working copy) @@ -1,27 +0,0 @@ -// { dg-do compile } -// { dg-options "-std=gnu++0x" } - -// 2011-06-01 Paolo Carlini -// -// Copyright (C) 2011 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include - -typedef std::unordered_multimap ummtype; - -static_assert(std::is_nothrow_move_constructible::value, "Error"); Index: testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc =================================================================== --- testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc (revision 178397) +++ testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc (working copy) @@ -1,27 +0,0 @@ -// { dg-do compile } -// { dg-options "-std=gnu++0x" } - -// 2011-06-01 Paolo Carlini -// -// Copyright (C) 2011 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include - -typedef std::unordered_set ustype; - -static_assert(std::is_nothrow_move_constructible::value, "Error"); Index: testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc =================================================================== --- testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc (revision 178397) +++ testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc (working copy) @@ -1,27 +0,0 @@ -// { dg-do compile } -// { dg-options "-std=gnu++0x" } - -// 2011-06-01 Paolo Carlini -// -// Copyright (C) 2011 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include - -typedef std::unordered_multiset umstype; - -static_assert(std::is_nothrow_move_constructible::value, "Error");