From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68813 invoked by alias); 3 Sep 2015 21:49:52 -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 68772 invoked by uid 48); 3 Sep 2015 21:49:49 -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: Thu, 03 Sep 2015 21:49: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: bug_status resolution 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/msg00309.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56568 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #2 from Jonathan Wakely --- (In reply to fuzzyTew from comment #1) > Here's an example I ran into using a plain int: > http://coliru.stacked-crooked.com/a/1dfad4e209339aa1 That's undefined behaviour. You create a temporary array with one element, then return an initializer_list which is bound to that local array, which goes out of scope. Your example and the original testcase are equivalent to: const int& f() { long i = 0; return i; } which creates a temporary and binds a reference to it, resulting in a dangling reference. std::initializer_list is not a container, don't try to do clever things with it, you will get burnt.