From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106028 invoked by alias); 1 Oct 2016 10:33:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 105816 invoked by uid 89); 1 Oct 2016 10:33:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=spoke, super 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; Sat, 01 Oct 2016 10:33:19 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 EDFF569CD7; Sat, 1 Oct 2016 10:33:17 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u91AXF0o025683; Sat, 1 Oct 2016 06:33:16 -0400 Subject: Re: [RFA 02/22] Use RAII to save and restore scalars To: Tom Tromey References: <1474949330-4307-1-git-send-email-tom@tromey.com> <1474949330-4307-3-git-send-email-tom@tromey.com> <20160927085937.com7c7ct4wuchzpg@ball> <87wphtfmcj.fsf@tromey.com> <579b45a0-2393-bda9-a244-cb2f7611635f@redhat.com> <87k2dsg1ul.fsf@tromey.com> <87fuogg0jr.fsf@tromey.com> Cc: Trevor Saunders , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <01d6497c-7421-d234-e5b3-60a825b43c36@redhat.com> Date: Sat, 01 Oct 2016 10:33:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <87fuogg0jr.fsf@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-10/txt/msg00007.txt.bz2 On 10/01/2016 05:23 AM, Tom Tromey wrote: > Pedro> Guess we could have the copy constructor actually move instead of > Pedro> copy, setting the copied-from's pointer member to NULL, and then > Pedro> have the destructor do nothing if the pointer is NULL. > > Tom> Yeah. I took this approach. I'm not super thrilled with it, but at the > Tom> same time it's not *too* bad. > > Scratch that, I spoke too soon. I couldn't get this to work. > > I don't understand why the 2-argument form of make_scoped_restore > requires a copy constructor while the 1-argument form does not. > > However, once you need a copy constructor, it doesn't seem possible > without a move constructor. The issue is that a copy constructor take a > const reference, so you can't modify the fields of the original. You can -- make the fields mutable. That's what ScopeGuard does too. > > Removing the 2-argument form seems to work. Though like I said, I don't > know why. I can't tell off hand. Maybe seeing the code would suggest something. > > > Also, as an aside, I found I was using nullptr in my patches, but this > isn't C++03. I think -std=c++03 is going to be needed or else it will > be too easy to slip in C++11-isms. Now, I do think C++11 is really much > better, but my understanding is that C++03 is what gdb decided on. I'm very much against forcing -std=c++03. My plan is to allow compiling with C++11 too, and use some of its features, for extra safety and extra efficiency, as long as we have C++03 fallbacks in place. If we force -std=c++03, that becomes impossible. I recently elaborated on this here: https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01624.html The gist is that I think that the features supported by compilers that people are using in practice to build gdb with is what matters in the end, not really C++03 vs C++11. The only reason we're not requiring C++11 is that some people still wanted to build gdb with older compilers that don't support it. That was last revisited a year ago when we discussed whether to go C++ or not in the first place. It may be that the baseline might have advanced meanwhile. Thanks, Pedro Alves