1 Return-Path: <Vladimir.Marek@Oracle.COM>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id B11ED431FBC
\r
6 for <notmuch@notmuchmail.org>; Tue, 30 Apr 2013 01:51:32 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 1ahaPOuZ2KbI for <notmuch@notmuchmail.org>;
\r
17 Tue, 30 Apr 2013 01:51:26 -0700 (PDT)
\r
18 Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69])
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id DD646431FAF
\r
22 for <notmuch@notmuchmail.org>; Tue, 30 Apr 2013 01:51:26 -0700 (PDT)
\r
23 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238])
\r
24 by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with
\r
25 ESMTP id r3U8pAGp004285
\r
26 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
\r
27 Tue, 30 Apr 2013 08:51:11 GMT
\r
28 Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231])
\r
29 by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id
\r
31 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL);
\r
32 Tue, 30 Apr 2013 08:51:07 GMT
\r
33 Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71])
\r
34 by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id
\r
35 r3U8p6U3016009; Tue, 30 Apr 2013 08:51:06 GMT
\r
36 Received: from pub.cz.oracle.com (/10.163.101.122)
\r
37 by default (Oracle Beehive Gateway v4.0)
\r
38 with ESMTP ; Tue, 30 Apr 2013 01:51:06 -0700
\r
39 Date: Tue, 30 Apr 2013 10:48:52 +0200
\r
40 From: Vladimir Marek <Vladimir.Marek@Oracle.COM>
\r
41 To: Kim Minh Kaplan <kimminh.kaplan+nomuch@afnic.fr>
\r
42 Subject: Re: [PATCH] don't store temporary value returned from c_str()
\r
43 Message-ID: <20130430084852.GA19599@pub.cz.oracle.com>
\r
44 Mail-Followup-To: Kim Minh Kaplan <kimminh.kaplan+nomuch@afnic.fr>,
\r
45 Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org,
\r
46 Vladimir Marek <vlmarek@volny.cz>
\r
47 References: <1366405933-17223-1-git-send-email-Vladimir.Marek@oracle.com>
\r
48 <m2sj2cjp2b.fsf@guru.guru-group.fi>
\r
49 <20130427101134.GI10394@pub.cz.oracle.com>
\r
50 <8761z4h7ih.fsf@kaki.tech.prive.nic.fr>
\r
52 Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN"
\r
53 Content-Disposition: inline
\r
54 Content-Transfer-Encoding: 8bit
\r
55 In-Reply-To: <8761z4h7ih.fsf@kaki.tech.prive.nic.fr>
\r
56 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
57 X-Source-IP: acsinet22.oracle.com [141.146.126.238]
\r
58 Cc: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org,
\r
59 Vladimir Marek <vlmarek@volny.cz>
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Tue, 30 Apr 2013 08:51:32 -0000
\r
76 Content-Type: text/plain; charset=utf-8
\r
77 Content-Disposition: inline
\r
78 Content-Transfer-Encoding: 8bit
\r
82 Thank you, I found it eventually too. But I wrote little test program
\r
83 (attached) which confused me. I haven't had much time to take a look
\r
84 into it since weekend.
\r
86 The idea is to have temporary object where I can detect whether
\r
87 destructor was called.
\r
91 printf ("%s\n", s.c_str());
\r
99 will print "destroyed"
\r
101 On my machine both prints "destroyed".
\r
104 I still believe my fix is correct, but I'm not at the position to be
\r
105 able to defend it at the moment :)
\r
111 > The january 2012 working draft:
\r
112 > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf
\r
114 > 12.2 Temporary objects [class.temporary]
\r
116 > 1 Temporaries of class type are created in various contexts: binding a
\r
117 > reference to a prvalue (8.5.3), returning a prvalue (6.6.3) […]
\r
119 > 3 When an implementation introduces a temporary object of a class that
\r
120 > has a non-trivial constructor (12.1, 12.8), it shall ensure that a
\r
121 > constructor is called for the temporary object. Similarly, the
\r
122 > destructor shall be called for a temporary with a non-trivial destructor
\r
123 > (12.4). Temporary objects are destroyed as the last step in evaluating
\r
124 > the full-expression (1.9) that (lexically) contains the point where they
\r
128 Content-Type: text/plain; charset=utf-8
\r
129 Content-Disposition: attachment; filename="a.cc"
\r
133 #include <string.h>
\r
135 using namespace std;
\r
142 array(int size):impl(size) { }
\r
143 array(array &in):impl(in.impl) { }
\r
146 operator[](size_t i) {
\r
151 strcpy(&impl[0], "destroyed");
\r
160 str(const char *input):tmp(100) {
\r
161 strcpy(tmp[0], input);
\r
164 const char* c_str() {
\r
165 return (array(tmp))[0];
\r
171 main (int argc, char **argv)
\r
175 printf ("%s\n", s.c_str());
\r
177 printf ("%s\n", x);
\r
181 --J/dobhs11T7y2rNN--
\r