From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18269 invoked by alias); 30 Sep 2016 23:50:52 -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 55137 invoked by uid 89); 30 Sep 2016 23:20:13 -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=H*M:bda9 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; Fri, 30 Sep 2016 23:20:12 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 1B89DC0528BB; Fri, 30 Sep 2016 23:20:11 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8UNK9TF028962; Fri, 30 Sep 2016 19:20:09 -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> Cc: Trevor Saunders , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <579b45a0-2393-bda9-a244-cb2f7611635f@redhat.com> Date: Fri, 30 Sep 2016 23:51: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: <87wphtfmcj.fsf@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-09/txt/msg00445.txt.bz2 On 09/30/2016 04:17 PM, Tom Tromey wrote: >>>>>> "Pedro" == Pedro Alves writes: > > Pedro> scoped_restore scope = make_scoped_restore (&some_global); > > I made this change. One minor oddity is that the 2-argument form of > make_scoped_restore required a copy constructor in the > scoped_restore_tmpl subclass. I think that's harmless though. Yeah. We just need to make sure that if a copy constructor does run, the code behaves as if it hadn't. My earlier comment on that not mattering may have been incorrect - if the copied-from scoped_restore is destructed before the make_scoped_restore function returns, then the global will revert back to the original value too soon. Guess we could have the copy constructor actually move instead of copy, setting the copied-from's pointer member to NULL, and then have the destructor do nothing if the pointer is NULL. Thanks, Pedro Alves