From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11300 invoked by alias); 21 Nov 2012 20:18:18 -0000 Received: (qmail 11286 invoked by uid 22791); 21 Nov 2012 20:18:16 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Nov 2012 20:18:10 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qALKIASM026692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 21 Nov 2012 15:18:10 -0500 Received: from host2.jankratochvil.net (ovpn-116-39.ams2.redhat.com [10.36.116.39]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qALKI675030123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 21 Nov 2012 15:18:08 -0500 Date: Wed, 21 Nov 2012 20:18:00 -0000 From: Jan Kratochvil To: Pedro Alves Cc: Tom Tromey , gdb@sourceware.org Subject: Re: Will therefore GDB utilize C++ or not? Message-ID: <20121121201805.GA1709@host2.jankratochvil.net> References: <20120330161403.GA17891@host2.jankratochvil.net> <87aa2rjkb8.fsf@fleche.redhat.com> <4F832D5B.9030308@redhat.com> <20120409190519.GA524@host2.jankratochvil.net> <4F833D29.4050102@redhat.com> <8762cwpz3u.fsf@fleche.redhat.com> <4FBA6D04.7060804@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4FBA6D04.7060804@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2012-11/txt/msg00063.txt.bz2 On Mon, 21 May 2012 18:27:48 +0200, Pedro Alves wrote: > What I meant by not that different, is, that with RAII you get > to write something like (the dumbest version of a RAII object > that supports canceling possible): > > class my_raii_thing > { > private: > whatever_arg *arg; << moral equivalent of the cleanup args. > bool discarded; > > public: > my_raii_thing (whatever_arg *p) : arg (p), discarded(false) > {} > > ~my_raii_thing () << moral equivalent of a cleanup function. > { > if (!discarded) > { > // whatever to release this->arg or something like that. > } > } > > void discard () > { > discarded = true; > } > }; > > and then do: > > my_raii_thing foo (&whatever_arg); > > if (whatnot) > { > whatever_arg.discard(); > return SUCESS; > } > } I find it too complicated, why not just shared_ptr: #include #include using namespace std; class R { public: R() { cout << "R new" << endl; } ~R() { cout << "R delete" << endl; } string val() { return "isR"; } }; static shared_ptr getR(bool fail) { auto v=shared_ptr(new R()); if (fail) throw fail; return v; } int main() { try { getR(true); } catch (...) {} cout << getR(false)->val() << endl; } R new R delete R new isR R delete As C++11 dependency is probably too strict one can use Boost instead and as GDB does not like external dependencies stripped down Boost can be bundled to the sourceware repository - on normal systems sure C++11 libraries get used instead. Jan