From patchwork Thu Oct 6 20:17:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 679062 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sqkVH3Xxxz9sDG for ; Fri, 7 Oct 2016 07:17:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=qxL6/n7z; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:references:message-id:date:mime-version:in-reply-to :content-type; q=dns; s=default; b=tu6xYLesnBs3uG35Qj8mCfez5V/aJ 9p6CvV7px+CuDpOxWAdnxRKq/ZxAc6+bBt7ZrS24wl2leVyCbzSKDm92MFQ6C3PZ AC+fStqdhlSc9Du9J6whHUIrkyonyrahLH2bT7lFeIRF6RFcH1/z30yGIivL8cYs D7lz0XBIZvHlLk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:references:message-id:date:mime-version:in-reply-to :content-type; s=default; bh=s3hIMaT9Wo6n8WsjwraPfPztxLI=; b=qxL 6/n7z4R/joDalgs4mMH9Hy9725lAktYqPj/DuRWQB5gaDXn2a4yOVe5GUy+dj71h k0bID+qTZKGxN7zqv3M2BJ8AoaEG3Bt0DCi3mjfiNtXlmdOmni8vz5Os7N9VceCu lmjICWFt6OKlqIghuPGqtIaKuXF4REDTt+8lSfms= Received: (qmail 11456 invoked by alias); 6 Oct 2016 20:17:42 -0000 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 Received: (qmail 11431 invoked by uid 89); 6 Oct 2016 20:17:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=losing, 831, 7, 8317 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Oct 2016 20:17:39 +0000 Received: by mail-wm0-f51.google.com with SMTP id k125so348240828wma.1; Thu, 06 Oct 2016 13:17:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to; bh=Fr4zfc4pdFddmZsIB4mU/Sk8zGR5G7OovzAxG+g8HEE=; b=bW0sVmjfDP/n/ORhwyCNJdnUKXZ3utKe1X7oJOKEM+5mKxe2nUls5XSm+kSATLGKdG q5RBeyBB+WVWTKBLeV9wJy8bgvAOFqxi9C7i27mJu1i1Ng8LmaxRiwz9RTTmn7CxJ9b3 /MYmJup64gBBNndHWOueso3fSK+LK1yj+88Cu52x7KdT/4ws2oqTpA4o5sVRzR7cTCKA Rt71bGL2kq60jme0cBrxvUGnexVMzbAOKKC0iY6fs+jFxh/6lLR7hda/F3WNEfrfhZ98 daRbnEAeVxwGyM+wkB2IS9zDe88hW8y57pAvK08JtrUcyKFxghCpEnlHFmGnafpSx+KY fr1g== X-Gm-Message-State: AA6/9RlxA5iTScXPmyuZ/KRqcCklMO+g7WhbWOyAMD7MRorUVmWRxVmxzLKJqfkIgWyduQ== X-Received: by 10.28.26.86 with SMTP id a83mr1560270wma.10.1475785056924; Thu, 06 Oct 2016 13:17:36 -0700 (PDT) Received: from [192.168.0.23] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id m75sm37042561wmi.0.2016.10.06.13.17.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 13:17:35 -0700 (PDT) From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: Re: [PATCH] 77864 Fix noexcept conditions for map/set default constructors To: libstdc++@gcc.gnu.org, gcc-patches References: <20161005115617.GA5501@redhat.com> <20161005121309.GM29482@redhat.com> Message-ID: <4d30deb3-8720-2aa6-d0f2-94f6fca44825@gmail.com> Date: Thu, 6 Oct 2016 22:17:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20161005121309.GM29482@redhat.com> On 05/10/2016 14:13, Jonathan Wakely wrote: > On 05/10/16 14:10 +0200, Marc Glisse wrote: >> On Wed, 5 Oct 2016, Jonathan Wakely wrote: >> >>> I added conditional noexcept to maps and sets, but forgot to account >>> for the comparison function, which could throw when constructed. >> >> IMO you are fighting a losing battle. We should implement >> noexcept(auto) (possibly with some private __noexcept_auto__ >> spelling) and just use that in most places where we want a >> conditional noexcept. > > That would be nice, but beyond my ability :-) > > So until then we can either remove the exception specs entirely, or > make them correct. > > Another approach is to rely on existing compiler ability to compute conditional noexcept when defaulting implementations. This is what I have done in this patch. The new default constructor on _Rb_tree_node_base is not a problem as it is not used to build _Rb_tree_node. I'll try to do the same for copy constructor/assignment and move constructor/assignment. * include/bits/stl_map.h (map()): Make default. * include/bits/stl_multimap.h (multimap()): Likewise. * include/bits/stl_multiset.h (multiset()): Likewise. * include/bits/stl_set.h (set()): Likewise. * include/bits/stl_tree.h (_Rb_tree_node_base()): New. (_Rb_tree_impl()): Make default. (_Rb_tree_impl::_M_initialize()): Delete. (_Rb_tree()): Make default. Tested under Linux x86_64, ok to commit ? François diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index e5b2a1b..dea7d5b 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -167,11 +167,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Default constructor creates no elements. */ - map() - _GLIBCXX_NOEXCEPT_IF( - is_nothrow_default_constructible::value - && is_nothrow_default_constructible::value) - : _M_t() { } +#if __cplusplus < 201103L + map() : _M_t() { } +#else + map() = default; +#endif /** * @brief Creates a %map with no elements. diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h index d240427..7e86b76 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -164,11 +164,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Default constructor creates no elements. */ - multimap() - _GLIBCXX_NOEXCEPT_IF( - is_nothrow_default_constructible::value - && is_nothrow_default_constructible::value) - : _M_t() { } +#if __cplusplus < 201103L + multimap() : _M_t() { } +#else + multimap() = default; +#endif /** * @brief Creates a %multimap with no elements. diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index cc068a9..7fe2fbd 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -144,11 +144,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Default constructor creates no elements. */ - multiset() - _GLIBCXX_NOEXCEPT_IF( - is_nothrow_default_constructible::value - && is_nothrow_default_constructible::value) - : _M_t() { } +#if __cplusplus < 201103L + multiset() : _M_t() { } +#else + multiset() = default; +#endif /** * @brief Creates a %multiset with no elements. diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index 3938351..5ed9672 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -147,11 +147,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Default constructor creates no elements. */ - set() - _GLIBCXX_NOEXCEPT_IF( - is_nothrow_default_constructible::value - && is_nothrow_default_constructible::value) - : _M_t() { } +#if __cplusplus < 201103L + set() : _M_t() { } +#else + set() = default; +#endif /** * @brief Creates a %set with no elements. diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index ee2dc70..ed575d0 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -108,6 +108,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Base_ptr _M_left; _Base_ptr _M_right; + _Rb_tree_node_base() _GLIBCXX_NOEXCEPT + : _M_color(_S_red), _M_parent(0), _M_left(this), _M_right(this) + { } + static _Base_ptr _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT { @@ -603,23 +607,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Key_compare _M_key_compare; _Rb_tree_node_base _M_header; +#if __cplusplus < 201103L size_type _M_node_count; // Keeps track of size of tree. +#else + size_type _M_node_count = 0; // Keeps track of size of tree. +#endif +#if __cplusplus < 201103L _Rb_tree_impl() : _Node_allocator(), _M_key_compare(), _M_header(), _M_node_count(0) - { _M_initialize(); } + { } +#else + _Rb_tree_impl() = default; +#endif _Rb_tree_impl(const _Key_compare& __comp, const _Node_allocator& __a) - : _Node_allocator(__a), _M_key_compare(__comp), _M_header(), - _M_node_count(0) - { _M_initialize(); } + : _Node_allocator(__a), _M_key_compare(__comp), _M_header() +#if __cplusplus < 201103L + , _M_node_count(0) +#endif + { } #if __cplusplus >= 201103L _Rb_tree_impl(const _Key_compare& __comp, _Node_allocator&& __a) - : _Node_allocator(std::move(__a)), _M_key_compare(__comp), - _M_header(), _M_node_count(0) - { _M_initialize(); } + : _Node_allocator(std::move(__a)), _M_key_compare(__comp), + _M_header() + { } #endif void @@ -630,16 +644,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->_M_header._M_right = &this->_M_header; this->_M_node_count = 0; } - - private: - void - _M_initialize() - { - this->_M_header._M_color = _S_red; - this->_M_header._M_parent = 0; - this->_M_header._M_left = &this->_M_header; - this->_M_header._M_right = &this->_M_header; - } }; _Rb_tree_impl<_Compare> _M_impl; @@ -831,7 +835,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: // allocation/deallocation +#if __cplusplus < 201103L _Rb_tree() { } +#else + _Rb_tree() = default; +#endif _Rb_tree(const _Compare& __comp, const allocator_type& __a = allocator_type())