From patchwork Tue Oct 25 19:55:27 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: 79270 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp43363qge; Tue, 25 Oct 2016 12:56:03 -0700 (PDT) X-Received: by 10.98.72.86 with SMTP id v83mr8330563pfa.148.1477425362916; Tue, 25 Oct 2016 12:56:02 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id lq6si8614762pab.318.2016.10.25.12.56.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2016 12:56:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439547-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439547-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439547-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=LDGUycJgLF20GIMfF lSgGwTvLrEncSS9m8kJ3Dtkd0UqUdTDzn6r0SWiWhGL+UEYGE4Ogfin/99kXBZLj Nztuq2PN0ioFLH+peFMlGXvXRqZpLvE10w83fU63fSZYJhTV2BFZDkGoVckPXLbp 8p+qVgmJjBj7X/zrqBr2RDi7RA= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=HM3x/wR0O428gNnc3fFNt4v HswA=; b=EY86nBeIc+VDZ41WcrR8KAD1H2IiYftJiM4iInqTcPcCYvNMLh36GK5 Y0ayacbGrkFm/fMqJtB4/8NCiC/XsJ1668187Yb3heTa0LNUJ4Q/VeiDPkpVtiCK r+YoX6OjmJCW/qIQxX8yWHICX2p9m1YFkynOBJCc34YlhTGhRsv0= Received: (qmail 34093 invoked by alias); 25 Oct 2016 19:55:34 -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 33428 invoked by uid 89); 25 Oct 2016 19:55:33 -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=83411, 834, 11, containers, synopses X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Oct 2016 19:55:31 +0000 Received: by mail-wm0-f67.google.com with SMTP id 79so1964202wmy.4; Tue, 25 Oct 2016 12:55:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=rMcHeJV9Kni33InDUTlUEVpLY7gdqvEnUfYkmGNejEM=; b=PlGvFRVU20J8Fd24UhdhAxXSuBilLs+phQ4L5X/9r6Xyn52mgAUp/6aiOU0GV59JXp hknOGfulG5MdCbQKVIS/eEB4lggn8DjoJqd8GERYedXlX6JfUM2OjI9Bxm/wg9fWIB65 2LehHDQ55zfogq5qGjWznnydW3ecezhDBCENR01rsQjv1VxJMDraDDOnHZeDWkHCdLI2 OdzyX+XyNag2+hqdhDo1OmHVTl5p9GsEkMZiiO3Od8GBhubwp2JZYsNY7FOc6YT0PwRo tp7yVUiRnV8jKEhW9fISpJWOS12mqqhFTD/KDnKHgfx+OFhD3c695t5wu7P+h5GgJJ+P utFg== X-Gm-Message-State: ABUngvd38rC8Z7jE2kZTHv9YIM9UU4bVxz3hUYt8RryAOcsL4SCQ1LdVJbuMcsApXSPicw== X-Received: by 10.28.19.131 with SMTP id 125mr4604292wmt.133.1477425329040; Tue, 25 Oct 2016 12:55:29 -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 g9sm26845943wjk.25.2016.10.25.12.55.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2016 12:55:28 -0700 (PDT) Subject: Re: [PATCH] 77864 Fix noexcept conditions for map/set default constructors To: Jonathan Wakely References: <20161005121309.GM29482@redhat.com> <4d30deb3-8720-2aa6-d0f2-94f6fca44825@gmail.com> <20161006213408.GU29482@redhat.com> <60454696-88fc-d7c0-12f5-b0f7e960dba8@gmail.com> <20161009151451.GB25380@redhat.com> <3daba99f-0630-2daf-6975-d93cc4d0cd7b@gmail.com> <7363dc77-9f64-f2f7-35ea-163f5486f66f@gmail.com> <20161024110336.GI2922@redhat.com> Cc: Tim Song , libstdc++@gcc.gnu.org, gcc-patches From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Message-ID: <400a3910-c407-1071-5721-4e410d293c21@gmail.com> Date: Tue, 25 Oct 2016 21:55:27 +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: <20161024110336.GI2922@redhat.com> On 24/10/2016 13:03, Jonathan Wakely wrote: > On 12/10/16 22:36 +0200, François Dumont wrote: >> On 10/10/2016 23:01, Tim Song wrote: >>> Trying again...with a few edits. >>> >>>> On Mon, Oct 10, 2016 at 3:24 PM, François Dumont >>>> >>>> wrote: >>>> >>>> @@ -602,24 +612,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >>>> struct _Rb_tree_impl : public _Node_allocator >>>> { >>>> _Key_compare _M_key_compare; >>>> - _Rb_tree_node_base _M_header; >>>> + _Rb_header_node _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(); } >>>> + : _M_node_count(0) >>>> + { } >>>> +#else >>>> + _Rb_tree_impl() = default; >>>> +#endif >>> >>> The default constructor of the associative containers is required to >>> value-initialize the comparator (see their synopses in >>> [map/set/multimap/multiset.overview]). >> I don't have latest Standard version so can't see the exact word but >> I find quite annoying that the Standard doesn't allow this simple >> implementation. >> >> I don't know if unodered containers have same kind of requirements >> for equal or hash functors but if so current implementation doesn't >> do this value initialization. >> >> So here is another attempt. This time it simply allows to have >> noexcept condition in one place and closer to where operations are >> being invoked. >> >> Ok to commit after tests ? >> >> François >>> >>> _Rb_tree_impl() = default; doesn't do that; it default-initializes the >>> comparator instead. >>> >>> Tim >>> >> > >> 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..b6a3c1e 100644 >> --- a/libstdc++-v3/include/bits/stl_tree.h >> +++ b/libstdc++-v3/include/bits/stl_tree.h >> @@ -137,6 +137,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> } >> }; >> >> + struct _Rb_header_node : public _Rb_tree_node_base >> + { >> + _Rb_header_node() _GLIBCXX_NOEXCEPT >> + { >> + _M_color = _S_red; >> + _M_parent = _Base_ptr(); >> + _M_left = _M_right = this; >> + } >> + }; >> + >> template >> struct _Rb_tree_node : public _Rb_tree_node_base >> { >> @@ -602,24 +612,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> struct _Rb_tree_impl : public _Node_allocator >> { >> _Key_compare _M_key_compare; >> - _Rb_tree_node_base _M_header; >> + _Rb_header_node _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 >> >> _Rb_tree_impl() >> - : _Node_allocator(), _M_key_compare(), _M_header(), >> - _M_node_count(0) >> - { _M_initialize(); } >> + _GLIBCXX_NOEXCEPT_IF( >> + is_nothrow_default_constructible<_Node_allocator>::value >> + && is_nothrow_default_constructible<_Key_compare>::value) >> + : _M_key_compare() >> +#if __cplusplus < 201103L >> + , _M_node_count(0) >> +#endif >> + { } > > I still think this part is pointless. Why use conditional compilation > here, when we could just always set it to zero? > > What is the advantage of using #if here, except adding more lines of > code? > >> >> _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) >> +#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) >> + { } >> #endif >> >> void >> @@ -630,16 +650,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; >> - } }; > > Since we can't remove the constructors that called _M_initialize() we > don't need to get rid of _M_initialize() either. That means we don't > need the _Rb_header_node type (so don't need to produce RTTI for a new > type). > > The purpose of the patch is to allow _Rb_tree() = default and then > set() = default, map() = default etc. > > That can be done by simply putting the _GLIBCXX_NOEXCEPT_IF on > _Rb_tree_impl() and forgetting all the other changes to _Rb_tree_impl. > Using a default member initializer for _M_node_count and removing > _M_initialize() aren't necessary to achieve the purpose of the patch Indeed, here is the simplified patch. But I will come back to this base type for the next patch to generalize the defaulted constructors and assignment operators. 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..0bc5f4b 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -606,6 +606,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION size_type _M_node_count; // Keeps track of size of tree. _Rb_tree_impl() + _GLIBCXX_NOEXCEPT_IF( + is_nothrow_default_constructible<_Node_allocator>::value + && is_nothrow_default_constructible<_Key_compare>::value) : _Node_allocator(), _M_key_compare(), _M_header(), _M_node_count(0) { _M_initialize(); } @@ -831,7 +834,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())