From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14578 invoked by alias); 8 Mar 2013 08:40:54 -0000 Received: (qmail 9029 invoked by uid 48); 8 Mar 2013 08:39:34 -0000 From: "potswa at mac dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56568] New: std::initializer_list return value contents lost prematurely Date: Fri, 08 Mar 2013 08:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: potswa at mac dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00634.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56568 Bug #: 56568 Summary: std::initializer_list return value contents lost prematurely Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: potswa@mac.com See http://stackoverflow.com/q/15286450/153285 This program segfaults: #include #include #include int main() { for ( auto && s : []() -> std::initializer_list< std::string > { return { std::string( "first" ), std::string( "second" ) }; }() ) std::cout << s << '\n'; } The return value object should be initialized from the braced-init-list, and bound directly to the implicit "auto && __range" object of the range-based for statement. The array backing that object should have the same lifetime as it, namely the duration of the loop. Instead, the array is destroyed when the lambda exits. This is not easy to fix, but I'll just file this.