From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61003 invoked by alias); 27 Sep 2016 08:50:54 -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 60993 invoked by uid 89); 27 Sep 2016 08:50:53 -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,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1539, his X-HELO: paperclip.tbsaunde.org Received: from tbsaunde.org (HELO paperclip.tbsaunde.org) (66.228.47.254) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Sep 2016 08:50:52 +0000 Received: from ball (fanzine.igalia.com [91.117.99.155]) by paperclip.tbsaunde.org (Postfix) with ESMTPSA id AE4D0C073; Tue, 27 Sep 2016 08:50:50 +0000 (UTC) Date: Tue, 27 Sep 2016 10:24:00 -0000 From: Trevor Saunders To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 02/22] Use RAII to save and restore scalars Message-ID: <20160927085937.com7c7ct4wuchzpg@ball> References: <1474949330-4307-1-git-send-email-tom@tromey.com> <1474949330-4307-3-git-send-email-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1474949330-4307-3-git-send-email-tom@tromey.com> User-Agent: NeoMutt/20160910 (1.7.0) X-SW-Source: 2016-09/txt/msg00362.txt.bz2 On Mon, Sep 26, 2016 at 10:08:30PM -0600, Tom Tromey wrote: > This patch replaces many (but not all) uses of > make_cleanup_restore_integer with a simple RAII-based template class. > It also removes the similar restore_execution_direction cleanup in > favor of this new class. Subsequent patches will replace other > similar cleanups with this class. > > I chose the name "scoped_restore" for this class. I considered that > perhaps "auto_restore" might be clearer. Or maybe something else; > it's simple enough to change. Its worth noting dmalcolm wants to add something similar to gcc for his rtl front end work. > I had hoped that template parameter deduction would work here, but it > did not, and so the patch uses explicit template parameters > everywhere. yeah, you can't deduce template args from a constructor in C++ > + // Create a new scoped_restore object that saves the current value > + // of *VAR, and then sets *VAR to VALUE. *VAR will be restored when > + // this scoped_restore object is destroyed. > + scoped_restore (T *var, T value) > + : saved_var (var), > + saved_value (*var) > + { > + *var = value; I wonder if it isn't clearer to create the scoped_restore and then set the variable yourself. > + // The saved variable. > + T *saved_var; > + > + // The saved value. > + T saved_value; I think you could use const T, but I doubt it matters, these objects really shouldn't have there address taken so the compiler should see everything about them. Trev