http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026
Matt Godbolt <matt at godbolt dot org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matt at godbolt dot org --- Comment #10 from Matt Godbolt <matt at godbolt dot org> 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<bool B> int func() { const int constVal = B ? 100 : -100; return [] { return constVal; }(); } int main(int, const char* []) { return func<true>(); // Returns 100 in -O0, but 0 in -O1 and above }