From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122821 invoked by alias); 9 Oct 2016 15:14:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 122803 invoked by uid 89); 9 Oct 2016 15:14:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Oct 2016 15:14:53 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90E5785543; Sun, 9 Oct 2016 15:14:52 +0000 (UTC) Received: from localhost (ovpn-116-122.ams2.redhat.com [10.36.116.122]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u99FEp2f007148; Sun, 9 Oct 2016 11:14:52 -0400 Date: Sun, 09 Oct 2016 15:14:00 -0000 From: Jonathan Wakely To: =?iso-8859-1?Q?Fran=E7ois?= Dumont Cc: libstdc++@gcc.gnu.org, gcc-patches Subject: Re: [PATCH] 77864 Fix noexcept conditions for map/set default constructors Message-ID: <20161009151451.GB25380@redhat.com> References: <20161005115617.GA5501@redhat.com> <20161005121309.GM29482@redhat.com> <4d30deb3-8720-2aa6-d0f2-94f6fca44825@gmail.com> <20161006213408.GU29482@redhat.com> <60454696-88fc-d7c0-12f5-b0f7e960dba8@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <60454696-88fc-d7c0-12f5-b0f7e960dba8@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) X-SW-Source: 2016-10/txt/msg00559.txt.bz2 On 08/10/16 22:55 +0200, François Dumont wrote: >On 06/10/2016 23:34, Jonathan Wakely wrote: >>On 06/10/16 22:17 +0200, François Dumont wrote: >>>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. >> >>Why not? > >_Rb_tree_node_base is used in 2 context. As member of _Rb_tree_impl in >which case we need the new default constructor. And also as base class >of _Rb_tree_node which is never constructed. Nodes are being allocated >and then associated value is being constructed through the allocator, >the node default constructor itself is never invoked. In C++03 mode that is true, but it's only valid because the type is trivially-constructible. If the type requires "non-vacuous initialization" then it's not valid to allocate memory for it and start using it without invoking a constructor. If you add a non-trivial constructor then we can't do that any more. In C++11 and later, see line 550 in ::new(__node) _Rb_tree_node<_Val>; This default-constructs a tree node. Currently there is no user-provided default constructor, so default-construction does no initialization. Adding your constructor would mean it is used for every node. > If you think it is cleaner to create an intermediate type that >will take care of this initialization through its default constructor >I can do that. > >> >>>I'll try to do the same for copy constructor/assignment and move >>>constructor/assignment. >> >>We need to make sure we don't change whether any of those operations >>are trivial (which shouldn't be a problem for copy/move, because they >>are definitely very non-trivial and will stay that way!) >> >>Does this change the default constructors from non-trivial to trivial? >It would be a major compiler bug if making a constructor default was >making it trivial. I must be misunderstanding you, because this is not a bug: #include struct A { A() { } }; static_assert( !std::is_trivially_default_constructible::value, "" ); struct B { B() = default; }; static_assert( std::is_trivially_default_constructible::value, "" );