From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7356 invoked by alias); 29 Jan 2013 13:31:20 -0000 Received: (qmail 7274 invoked by uid 48); 29 Jan 2013 13:31:02 -0000 From: "matt at godbolt dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52026] [c++0x] Constexpr Variable Appears Uninitialized in Lambda Date: Tue, 29 Jan 2013 13:31: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-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: matt at godbolt dot org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: 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-01/txt/msg02654.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026 Matt Godbolt changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matt at godbolt dot org --- Comment #10 from Matt Godbolt 2013-01-29 13:31:01 UTC --- I have a smaller reproduction case, and some extra information: References to non-explicitly captured constant values in template functions generate invalid code. An empty capture list fails to error, and generates invalid code. A catch-all capture list ([=] or [&]) correctly compiles, but generates invalid code. A capture list that explicitly captures the constant value by reference or value compiles and generates correct code. With -Wall -Wextra, the constant is flagged as "uninitialized". The code compiles and works correctly on GCC 4.5.2, but fails on GCC 4.6.3 and GCC 4.7.2. template int func() { const int constVal = B ? 100 : -100; return [] { return constVal; }(); } int main(int, const char* []) { return func(); // Returns 100 in -O0, but 0 in -O1 and above }