--- /dev/null
+Return-Path: <Vladimir.Marek@Oracle.COM>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id B11ED431FBC\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Apr 2013 01:51:32 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.299\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 1ahaPOuZ2KbI for <notmuch@notmuchmail.org>;\r
+ Tue, 30 Apr 2013 01:51:26 -0700 (PDT)\r
+Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id DD646431FAF\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Apr 2013 01:51:26 -0700 (PDT)\r
+Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238])\r
+ by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
+ ESMTP id r3U8pAGp004285\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
+ Tue, 30 Apr 2013 08:51:11 GMT\r
+Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231])\r
+ by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+ r3U8p65m016017\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL);\r
+ Tue, 30 Apr 2013 08:51:07 GMT\r
+Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71])\r
+ by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+ r3U8p6U3016009; Tue, 30 Apr 2013 08:51:06 GMT\r
+Received: from pub.cz.oracle.com (/10.163.101.122)\r
+ by default (Oracle Beehive Gateway v4.0)\r
+ with ESMTP ; Tue, 30 Apr 2013 01:51:06 -0700\r
+Date: Tue, 30 Apr 2013 10:48:52 +0200\r
+From: Vladimir Marek <Vladimir.Marek@Oracle.COM>\r
+To: Kim Minh Kaplan <kimminh.kaplan+nomuch@afnic.fr>\r
+Subject: Re: [PATCH] don't store temporary value returned from c_str()\r
+Message-ID: <20130430084852.GA19599@pub.cz.oracle.com>\r
+Mail-Followup-To: Kim Minh Kaplan <kimminh.kaplan+nomuch@afnic.fr>,\r
+ Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org,\r
+ Vladimir Marek <vlmarek@volny.cz>\r
+References: <1366405933-17223-1-git-send-email-Vladimir.Marek@oracle.com>\r
+ <m2sj2cjp2b.fsf@guru.guru-group.fi>\r
+ <20130427101134.GI10394@pub.cz.oracle.com>\r
+ <8761z4h7ih.fsf@kaki.tech.prive.nic.fr>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN"\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+In-Reply-To: <8761z4h7ih.fsf@kaki.tech.prive.nic.fr>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Source-IP: acsinet22.oracle.com [141.146.126.238]\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org,\r
+ Vladimir Marek <vlmarek@volny.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 30 Apr 2013 08:51:32 -0000\r
+\r
+\r
+--J/dobhs11T7y2rNN\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+\r
+Hi,\r
+\r
+Thank you, I found it eventually too. But I wrote little test program\r
+(attached) which confused me. I haven't had much time to take a look\r
+into it since weekend.\r
+\r
+The idea is to have temporary object where I can detect whether\r
+destructor was called.\r
+\r
+I thought that\r
+\r
+printf ("%s\n", s.c_str());\r
+will print "test"\r
+\r
+and\r
+\r
+x=s.c_str();\r
+printf ("%s\n", x);\r
+\r
+will print "destroyed"\r
+\r
+On my machine both prints "destroyed".\r
+\r
+\r
+I still believe my fix is correct, but I'm not at the position to be\r
+able to defend it at the moment :)\r
+\r
+Thank you\r
+-- \r
+ Vlad\r
+\r
+> The january 2012 working draft: \r
+> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf\r
+> \r
+> 12.2 Temporary objects [class.temporary]\r
+> \r
+> 1 Temporaries of class type are created in various contexts: binding a\r
+> reference to a prvalue (8.5.3), returning a prvalue (6.6.3) […]\r
+> \r
+> 3 When an implementation introduces a temporary object of a class that\r
+> has a non-trivial constructor (12.1, 12.8), it shall ensure that a\r
+> constructor is called for the temporary object. Similarly, the\r
+> destructor shall be called for a temporary with a non-trivial destructor\r
+> (12.4). Temporary objects are destroyed as the last step in evaluating\r
+> the full-expression (1.9) that (lexically) contains the point where they\r
+> were created.\r
+\r
+--J/dobhs11T7y2rNN\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: attachment; filename="a.cc"\r
+\r
+#include <stdio.h>\r
+#include <vector>\r
+#include <string.h>\r
+\r
+using namespace std;\r
+\r
+class array {\r
+ vector<char> impl;\r
+\r
+ public:\r
+\r
+ array(int size):impl(size) { }\r
+ array(array &in):impl(in.impl) { }\r
+\r
+ char*\r
+ operator[](size_t i) {\r
+ return &impl[i];\r
+ };\r
+\r
+ ~array() {\r
+ strcpy(&impl[0], "destroyed");\r
+ }\r
+};\r
+\r
+class str {\r
+ array tmp;\r
+\r
+ public:\r
+\r
+ str(const char *input):tmp(100) {\r
+ strcpy(tmp[0], input);\r
+ };\r
+\r
+ const char* c_str() {\r
+ return (array(tmp))[0];\r
+ };\r
+};\r
+\r
+\r
+int\r
+main (int argc, char **argv)\r
+{\r
+ str s("test");\r
+ const char *x;\r
+ printf ("%s\n", s.c_str());\r
+ x=s.c_str();\r
+ printf ("%s\n", x);\r
+ return 0;\r
+}\r
+\r
+--J/dobhs11T7y2rNN--\r