From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121874 invoked by alias); 4 Sep 2015 09:02:12 -0000 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 Received: (qmail 121831 invoked by uid 48); 4 Sep 2015 09:02:08 -0000 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56568] std::initializer_list return value contents lost prematurely Date: Fri, 04 Sep 2015 09:02:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-09/txt/msg00324.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56568 --- Comment #6 from Jonathan Wakely --- (In reply to fuzzyTew from comment #4) > I'm not as experienced in the details. I think perhaps my example is > invalid as you state but the original testcase is not (see &&). That makes no difference. Using my previous example, David's original testcase is roughly equivalent to: const int& f() { long i = 0; return i; } auto&& i = f(); It's irrelevant what you do with the result, f() returns a dangling reference to an object that doesn't exist after the function returns. (In reply to David Krauss from comment #5) > I'm working on an ISO proposal (http://bit.ly/genlife) to fix some such > cases in C++17, but all it would do for return values is allow the compiler > to produce a warning. The way initializer_list works, the sequence is > intrinsically incapable of escaping the current scope, much less the current > function. Right. I opened PR 67445 to suggest a warning for cases like this, but I don't expect it to be implemented any time soon.