From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3047 invoked by alias); 9 Aug 2008 02:25:43 -0000 Received: (qmail 3031 invoked by uid 22791); 9 Aug 2008 02:25:42 -0000 X-Spam-Check-By: sourceware.org Received: from exprod6og103.obsmtp.com (HELO exprod6og103.obsmtp.com) (64.18.1.185) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 09 Aug 2008 02:25:01 +0000 Received: from source ([192.150.11.134]) by exprod6ob103.postini.com ([64.18.5.12]) with SMTP; Fri, 08 Aug 2008 19:24:58 PDT Received: from inner-relay-1.corp.adobe.com ([153.32.1.51]) by outbound-smtp-1.corp.adobe.com (8.12.10/8.12.10) with ESMTP id m792LIG3011927; Fri, 8 Aug 2008 19:21:18 -0700 (PDT) Received: from fe1.corp.adobe.com (fe1.corp.adobe.com [10.8.192.70]) by inner-relay-1.corp.adobe.com (8.12.10/8.12.10) with ESMTP id m792Owiq018726; Fri, 8 Aug 2008 19:24:58 -0700 (PDT) Received: from namailgen.corp.adobe.com ([10.8.192.91]) by fe1.corp.adobe.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 8 Aug 2008 19:24:58 -0700 Received: from 10.7.234.18 ([10.7.234.18]) by namailgen.corp.adobe.com ([10.8.192.91]) via Exchange Front-End Server namail.corp.adobe.com ([10.8.189.97]) with Microsoft Exchange Server HTTP-DAV ; Sat, 9 Aug 2008 02:24:57 +0000 User-Agent: Microsoft-Entourage/12.11.0.080522 Date: Sat, 09 Aug 2008 02:44:00 -0000 Subject: Re: Is this code wrong? From: Eljay Love-Jensen To: John Fine CC: GCC-help Message-ID: In-Reply-To: <489CC728.5040603@verizon.net> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00082.txt.bz2 Hi John, The style that you indicated... Foo ReturnAFoo() { Foo foo; return foo; } void DoSomething() { Foo const& foo = ReturnAFoo(); foo.AreYouStillHere(); // Yep, still here. } ...is good. The temporary returned by ReturnAFoo in DoSomething is bound to the reference. It won't be destructed until the reference goes out of scope. Really. I use that style often. (Although I can't cite chapter+verse of ISO 14882.) HTH, --Eljay