--- /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 64D8E431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 1 May 2013 04:30:27 -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 lB+-6ahJ-ypu for <notmuch@notmuchmail.org>;\r
+ Wed, 1 May 2013 04:30:21 -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 309DA431FC0\r
+ for <notmuch@notmuchmail.org>; Wed, 1 May 2013 04:30:20 -0700 (PDT)\r
+Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237])\r
+ by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
+ ESMTP id r41BU6K2011375\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
+ Wed, 1 May 2013 11:30:07 GMT\r
+Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230])\r
+ by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+ r41BU4b0003921\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL);\r
+ Wed, 1 May 2013 11:30:04 GMT\r
+Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67])\r
+ by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+ r41BU36E003914; Wed, 1 May 2013 11:30:03 GMT\r
+Received: from pub.cz.oracle.com (/10.163.101.122)\r
+ by default (Oracle Beehive Gateway v4.0)\r
+ with ESMTP ; Wed, 01 May 2013 04:30:03 -0700\r
+Date: Wed, 1 May 2013 13:28:06 +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: <20130501112806.GD19599@pub.cz.oracle.com>\r
+Mail-Followup-To: Kim Minh Kaplan <kimminh.kaplan+nomuch@afnic.fr>,\r
+ Vladimir Marek <vlmarek@volny.cz>, Tomi Ollila <tomi.ollila@iki.fi>,\r
+ notmuch@notmuchmail.org\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
+ <20130430084852.GA19599@pub.cz.oracle.com>\r
+ <87ehdsfj4u.fsf@kaki.tech.prive.nic.fr>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+In-Reply-To: <87ehdsfj4u.fsf@kaki.tech.prive.nic.fr>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Source-IP: acsinet21.oracle.com [141.146.126.237]\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: Wed, 01 May 2013 11:30:27 -0000\r
+\r
+> You have to somehow instantiate a temporary object, using a function\r
+> call for example.\r
+> \r
+> #include <string.h>\r
+> #include <stdio.h>\r
+> struct example {\r
+> char data[10];\r
+> char *c_str() { return data; }\r
+> example() { strcpy(data, "test"); }\r
+> ~example() { strcpy(data, "destroyed"); }\r
+> };\r
+> example foo()\r
+> {\r
+> example res;\r
+> return res;\r
+> }\r
+> main()\r
+> {\r
+> printf("%s\n", foo().c_str());\r
+> char *x = foo().c_str();\r
+> printf("%s\n", x);\r
+> }\r
+\r
+Right. After more tests I think I'm getting hang of it. In my examples I\r
+had function similar to\r
+\r
+char *foo() {\r
+ example res;\r
+ return res.c_str();\r
+}\r
+\r
+In this case the reference returned is to _char pointer_ and not to\r
+example struct. So the struct is destroyed before returning from foo to\r
+caller. Compiler does not understand that the returned char pointer does\r
+not have any meaning without the example struct.\r
+\r
+This is where I was doing the mistake, I believe.\r
+\r
+Thank you\r
+-- \r
+ Vlad\r