public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "matt at godbolt dot org" <gcc-bugzilla@gcc.gnu.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	[thread overview]
Message-ID: <bug-52026-4-WvD4xnmZr3@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-52026-4@http.gcc.gnu.org/bugzilla/>


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
}


  parent reply	other threads:[~2013-01-29 13:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: " cheesear at gmail dot com
2012-01-28  4:57 ` [Bug c++/52026] " pinskia at gcc dot gnu.org
2012-08-08  8:58 ` slipstreamdrive at hotmail dot com
2012-08-08  9:01 ` slipstreamdrive at hotmail dot com
2012-08-17 15:35 ` jpalecek at web dot de
2012-08-19 14:05 ` jpalecek at web dot de
2012-08-19 14:14 ` jpalecek at web dot de
2012-08-19 14:38 ` paolo.carlini at oracle dot com
2012-08-19 15:38 ` jpalecek at web dot de
2012-08-20  9:07 ` paolo.carlini at oracle dot com
2013-01-29 13:31 ` matt at godbolt dot org [this message]
2013-02-14 23:54 ` [Bug c++/52026] [4.6/4.7/4.8 Regression] " paolo.carlini at oracle dot com
2013-02-15 16:17 ` jason at gcc dot gnu.org
2013-02-15 18:33 ` jason at gcc dot gnu.org
2013-02-15 18:39 ` jason at gcc dot gnu.org
2014-05-30 18:58 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-52026-4-WvD4xnmZr3@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).