public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
@ 2012-01-28  4:04 cheesear at gmail dot com
  2012-01-28  4:57 ` [Bug c++/52026] " pinskia at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: cheesear at gmail dot com @ 2012-01-28  4:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

             Bug #: 52026
           Summary: [c++0x] g++: Constexpr Variable Appears Uninitialized
                    in Lambda
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: cheesear@gmail.com


Created attachment 26487
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26487
The code sample exhibiting the suspected bug.

Hello everyone,

In the code fragment below, g++ (4.6.1 on Linux Mint 64-bit) complains that x
is uninitialized in the lambda function, and prints out an initialized value
from the stack for the last three lines of the program's output. I'd except all
four lines of the output to be '5', so I suspect that this may be a compiler
bug.

Also, even without the reference-capture in the lambda function, the code still
compiles. Below follows the command used to compile the code, along with one
possible output.

# g++ -Wall -std=c++0x c.cpp
c.cpp: In lambda function:
c.cpp:25:4: warning: ‘x’ is used uninitialized in this function
[-Wuninitialized]

# ./a.out
5
32535
32535
32535


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
@ 2012-01-28  4:57 ` pinskia at gcc dot gnu.org
  2012-08-08  8:58 ` slipstreamdrive at hotmail dot com
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-28  4:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-28
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-28 04:34:34 UTC ---
Confirmed.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda 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
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: slipstreamdrive at hotmail dot com @ 2012-08-08  8:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #2 from TbR <slipstreamdrive at hotmail dot com> 2012-08-08 08:57:49 UTC ---
Created attachment 27958
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27958
Code example to trigger the supposed bug.

only the "bug" function triggers the bug, while "nobug1" and "nobug2" don't.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda 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
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: slipstreamdrive at hotmail dot com @ 2012-08-08  9:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

TbR <slipstreamdrive at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slipstreamdrive at hotmail
                   |                            |dot com

--- Comment #3 from TbR <slipstreamdrive at hotmail dot com> 2012-08-08 09:01:39 UTC ---
Sorry, to make two comments. The bug is indeed not only showing a warning, but
the variable is uninitialized when executing the code.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (2 preceding siblings ...)
  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
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jpalecek at web dot de @ 2012-08-17 15:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

Jiří Paleček <jpalecek at web dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jpalecek at web dot de

--- Comment #4 from Jiří Paleček <jpalecek at web dot de> 2012-08-17 15:35:22 UTC ---
Could it be a duplicate of <a
href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53488">53488</a>?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (3 preceding siblings ...)
  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
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jpalecek at web dot de @ 2012-08-19 14:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #5 from Jiří Paleček <jpalecek at web dot de> 2012-08-19 14:04:34 UTC ---
*** Bug 53488 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (4 preceding siblings ...)
  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
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jpalecek at web dot de @ 2012-08-19 14:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #6 from Jiří Paleček <jpalecek at web dot de> 2012-08-19 14:13:44 UTC ---
BTW I have proposed a patch that fixes this problem here:
http://gcc.gnu.org/ml/gcc-patches/2012-08/msg01252.html. Please take a look at
it.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (5 preceding siblings ...)
  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
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-08-19 14:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-08-19 14:38:36 UTC ---
Do you have a copyright assignment on file?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (6 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jpalecek at web dot de @ 2012-08-19 15:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #8 from Jiří Paleček <jpalecek at web dot de> 2012-08-19 15:38:33 UTC ---
(In reply to comment #7)
> Do you have a copyright assignment on file?

I don't know what you're talking about, so probably no. (BTW which file?)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (7 preceding siblings ...)
  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 ` [Bug c++/52026] [c++0x] " matt at godbolt dot org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-08-20  9:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-08-20 09:07:26 UTC ---
That's a big problem if you are serious about contributing to gcc. See: 
http://gcc.gnu.org/contribute.html 

In short, if you don't want to waste time, make sure to obtain, fill and return
the forms before sending patches.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [c++0x] Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (8 preceding siblings ...)
  2012-08-20  9:07 ` paolo.carlini at oracle dot com
@ 2013-01-29 13:31 ` matt at godbolt dot org
  2013-02-14 23:54 ` [Bug c++/52026] [4.6/4.7/4.8 Regression] " paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: matt at godbolt dot org @ 2013-01-29 13:31 UTC (permalink / raw)
  To: gcc-bugs


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
}


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [4.6/4.7/4.8 Regression] Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (9 preceding siblings ...)
  2013-01-29 13:31 ` [Bug c++/52026] [c++0x] " matt at godbolt dot org
@ 2013-02-14 23:54 ` paolo.carlini at oracle dot com
  2013-02-15 16:17 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-14 23:54 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
            Summary|[c++0x] Constexpr Variable  |[4.6/4.7/4.8 Regression]
                   |Appears Uninitialized in    |Constexpr Variable Appears
                   |Lambda                      |Uninitialized in Lambda

--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-14 23:53:43 UTC ---
Seems indeed a regression.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [4.6/4.7/4.8 Regression] Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (10 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-15 16:17 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-15 16:17:31 UTC ---
Author: jason
Date: Fri Feb 15 16:17:25 2013
New Revision: 196081

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196081
Log:
    PR c++/52026
    * semantics.c (finish_id_expression): In a template, return
    the identifier for a constant variable.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [4.6/4.7/4.8 Regression] Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (11 preceding siblings ...)
  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
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-15 18:33 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-15 18:32:25 UTC ---
Author: jason
Date: Fri Feb 15 18:32:12 2013
New Revision: 196087

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196087
Log:
    PR c++/52026
    * semantics.c (finish_id_expression): In a template, return
    the identifier for a constant variable.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const2.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/semantics.c


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [4.6/4.7/4.8 Regression] Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (12 preceding siblings ...)
  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
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-15 18:39 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
   Target Milestone|---                         |4.7.3

--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-15 18:39:10 UTC ---
Fixed for 4.7.3.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/52026] [4.6/4.7/4.8 Regression] Constexpr Variable Appears Uninitialized in Lambda
  2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda cheesear at gmail dot com
                   ` (13 preceding siblings ...)
  2013-02-15 18:39 ` jason at gcc dot gnu.org
@ 2014-05-30 18:58 ` jason at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-30 18:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52026
Bug 52026 depends on bug 56947, which changed state.

Bug 56947 Summary: [4.7 Regression] Bogus 'XX' was not declared in this scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56947

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2014-05-30 18:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-28  4:04 [Bug c++/52026] New: [c++0x] g++: Constexpr Variable Appears Uninitialized in Lambda 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 ` [Bug c++/52026] [c++0x] " matt at godbolt dot org
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

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).