From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68683 invoked by alias); 17 Jan 2019 21:39:33 -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 68668 invoked by uid 89); 17 Jan 2019 21:39:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1646, H*f:sk:1014fa7, make_scope_exit, somewhere X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.218) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Jan 2019 21:39:30 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway31.websitewelcome.com (Postfix) with ESMTP id E42102942F for ; Thu, 17 Jan 2019 15:39:28 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id kFNogRQgQYTGMkFNogB3pg; Thu, 17 Jan 2019 15:39:28 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=vkhiQTJRZNSvvLRFSjuhpb/Ir9kgl/vvHpUrMghVJVk=; b=CSpCnHFxvaAzGTAZO9gZVzNJIz c24akZ6h5RZ23tAE/NIdsyPJQWDY064NoRKoUKoWWfzCUsNkmXSO1uf9m/QzWOt48zVyY2Cp/cxC8 nGTjFXC08uXvbor2IaWCxWnHo; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:47466 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gkFNo-000BSY-KI; Thu, 17 Jan 2019 15:39:28 -0600 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , Andrew Burgess , gdb-patches@sourceware.org Subject: Re: [PATCH 00/12] remove some cleanups using a cleanup function References: <20190109033426.16062-1-tom@tromey.com> <961d9501-23e6-9adb-a11b-da41702c4fa0@redhat.com> <20190115094157.GP3456@embecosm.com> <87ef9dttfl.fsf@tromey.com> <1014fa7f-bbce-cbea-f54f-480373299809@redhat.com> Date: Thu, 17 Jan 2019 21:39:00 -0000 In-Reply-To: (Pedro Alves's message of "Wed, 16 Jan 2019 23:10:23 +0000") Message-ID: <87ef9bm0a8.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-01/txt/msg00415.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> See patch below. Since cleanup_function turned into scope_exit, Pedro> this new class became forward_scope_exit, because it's a "forwarding" Pedro> version of scope_exit? I'm really not that sure about that name... Pedro> wrap_scope_exit came to mind too. Or maybe call it cleanup_function? The name seems reasonable enough to me. Pedro> Ideally we'd find a way to implement SCOPE_FAILURE/SCOPE_SUCCESS Pedro> in C++11 instead... Maybe we should start a C++17 meta-bug to collect future changes. Pedro> I think this is the first time I had found a use for a function-try-block, Pedro> see scope_exit ctor... TIL! Pedro> Here is patch with everything together. WDYT? I think it all looks good. One nit and one question... Pedro> +/* A forward_scope_exit is like scope_exit, but instead of giving it a Pedro> + callable, you instead specialize it for a given cleanup function, Pedro> + and the generated class automatically has a constructor with the I think it would make sense to explain the origin of the "forward" name somewhere in this comment. Pedro> +#define SCOPE_EXIT \ Pedro> + auto CONCAT(scope_exit_, __LINE__) = ::detail::scope_exit_lhs () + [&] () [...] Pedro> + auto invalidator Pedro> + = make_scope_exit ([&] { this->invalidate (regnum); }); In the current spots it doesn't matter, but I tend to think it's better to capture by value rather than by reference. The local being captured might well be reused in the function. On the other hand, this would be a difference from the spec. Tom