Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id BFA4A431FB6 for ; Tue, 30 Apr 2013 02:44:38 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uK63sFi3qoto for ; Tue, 30 Apr 2013 02:44:33 -0700 (PDT) Received: from mx4.nic.fr (mx4.nic.fr [192.134.4.12]) by olra.theworths.org (Postfix) with ESMTP id 37949431FAF for ; Tue, 30 Apr 2013 02:44:33 -0700 (PDT) Received: from mx4.nic.fr (localhost [127.0.0.1]) by mx4.nic.fr (Postfix) with SMTP id 46CE3280668; Tue, 30 Apr 2013 11:44:31 +0200 (CEST) Received: from relay2.nic.fr (relay2.nic.fr [192.134.4.163]) by mx4.nic.fr (Postfix) with ESMTP id 42142280617; Tue, 30 Apr 2013 11:44:31 +0200 (CEST) Received: from kaki.tech.prive.nic.fr (kaki.tech.prive.sqy.nic.fr [10.10.86.114]) by relay2.nic.fr (Postfix) with ESMTP id 405ECB38055; Tue, 30 Apr 2013 11:44:01 +0200 (CEST) Received: by kaki.tech.prive.nic.fr (Postfix, from userid 1000) id 245663F8139; Tue, 30 Apr 2013 09:44:01 +0000 (UTC) From: Kim Minh Kaplan To: Vladimir Marek Subject: Re: [PATCH] don't store temporary value returned from c_str() References: <1366405933-17223-1-git-send-email-Vladimir.Marek@oracle.com> <20130427101134.GI10394@pub.cz.oracle.com> <8761z4h7ih.fsf@kaki.tech.prive.nic.fr> <20130430084852.GA19599@pub.cz.oracle.com> Date: Tue, 30 Apr 2013 09:44:01 +0000 In-Reply-To: <20130430084852.GA19599@pub.cz.oracle.com> (Vladimir Marek's message of "Tue, 30 Apr 2013 10:48:52 +0200") Message-ID: <87ehdsfj4u.fsf@kaki.tech.prive.nic.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: Tomi Ollila , notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Apr 2013 09:44:38 -0000 Vladimir Marek=C2=A0: > Thank you, I found it eventually too. But I wrote little test program > (attached) which confused me. I haven't had much time to take a look > into it since weekend. > > The idea is to have temporary object where I can detect whether > destructor was called. > > I thought that > > printf ("%s\n", s.c_str()); > will print "test" > > and > > x=3Ds.c_str(); > printf ("%s\n", x); > > will print "destroyed" > > On my machine both prints "destroyed". You have to somehow instantiate a temporary object, using a function call for example. #include #include struct example { char data[10]; char *c_str() { return data; } example() { strcpy(data, "test"); } ~example() { strcpy(data, "destroyed"); } }; example foo() { example res; return res; } main() { printf("%s\n", foo().c_str()); char *x =3D foo().c_str(); printf("%s\n", x); } Kim Minh.