public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions
@ 2011-12-24 18:25 classixretrox at gmail dot com
  2011-12-24 18:40 ` [Bug c++/51675] " classixretrox at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: classixretrox at gmail dot com @ 2011-12-24 18:25 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51675
           Summary: [C++11][New in 4.7] Cannot create constexpr unions
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: classixretrox@gmail.com


union foo
{
    int x = 0;
    short y;

    constexpr foo() = default;
};

This code compiles under GCC 4.6, however, not GCC 4.7.  It works if I remove
the constexpr keyword.

Output of GCC:
test.cc:6:12: error: explicitly defaulted function ‘constexpr foo::foo()’
cannot be declared as constexpr because the implicit declaration is not
constexpr:
test.cc:4:8: note: defaulted default constructor does not initialize ‘short int
foo::y’

If I provide only one initialization, it tells me that the others are
initialized.  If I initialize the others, it tells me that I can't initialize
more than one.  It essentially prevents the creation of constexpr unions.


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

* [Bug c++/51675] [C++11][New in 4.7] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
@ 2011-12-24 18:40 ` classixretrox at gmail dot com
  2011-12-24 22:26 ` [Bug c++/51675] [C++11][4.7 Regression] " paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: classixretrox at gmail dot com @ 2011-12-24 18:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from RétroX <classixretrox at gmail dot com> 2011-12-24 18:24:45 UTC ---
More information: initializing in the constructor doesn't work, either.

union foo
{
    int x;
    short y;

    constexpr foo() : x(0) { }
};

Also does not compile.


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
  2011-12-24 18:40 ` [Bug c++/51675] " classixretrox at gmail dot com
@ 2011-12-24 22:26 ` paolo.carlini at oracle dot com
  2012-01-02  5:41 ` jason at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-12-24 22:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
            Summary|[C++11][New in 4.7] Cannot  |[C++11][4.7 Regression]
                   |create constexpr unions     |Cannot create constexpr
                   |                            |unions
           Severity|major                       |normal


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
  2011-12-24 18:40 ` [Bug c++/51675] " classixretrox at gmail dot com
  2011-12-24 22:26 ` [Bug c++/51675] [C++11][4.7 Regression] " paolo.carlini at oracle dot com
@ 2012-01-02  5:41 ` jason at gcc dot gnu.org
  2012-01-02 10:51 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2012-01-02  5:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-01-02
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (2 preceding siblings ...)
  2012-01-02  5:41 ` jason at gcc dot gnu.org
@ 2012-01-02 10:51 ` rguenth at gcc dot gnu.org
  2012-01-02 17:54 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-01-02 10:51 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.7.0


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (3 preceding siblings ...)
  2012-01-02 10:51 ` rguenth at gcc dot gnu.org
@ 2012-01-02 17:54 ` jason at gcc dot gnu.org
  2012-01-03 16:42 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2012-01-02 17:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2012-01-02 17:53:32 UTC ---
Author: jason
Date: Mon Jan  2 17:53:28 2012
New Revision: 182810

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182810
Log:
    DR 1359
    PR c++/51675
    * method.c (walk_field_subobs): Don't check for uninitialized
    fields in a union.
    (synthesized_method_walk): Check here.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-union2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/method.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (4 preceding siblings ...)
  2012-01-02 17:54 ` jason at gcc dot gnu.org
@ 2012-01-03 16:42 ` paolo.carlini at oracle dot com
  2012-02-03  6:24 ` nephatrine at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 16:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|jason at gcc dot gnu.org    |
         Resolution|                            |FIXED

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 16:41:08 UTC ---
Likewise fixed.


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (5 preceding siblings ...)
  2012-01-03 16:42 ` paolo.carlini at oracle dot com
@ 2012-02-03  6:24 ` nephatrine at gmail dot com
  2012-02-07  1:30 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: nephatrine at gmail dot com @ 2012-02-03  6:24 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Wolf <nephatrine at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nephatrine at gmail dot com

--- Comment #4 from Daniel Wolf <nephatrine at gmail dot com> 2012-02-03 06:24:12 UTC ---
(In reply to comment #1)
> More information: initializing in the constructor doesn't work, either.
> 
> union foo
> {
>     int x;
>     short y;
> 
>     constexpr foo() : x(0) { }
> };
> 
> Also does not compile.

This code does not compile with the latest trunk.

error: uninitialized member 'foo::y' in 'constexpr' constructor

> union foo
> {
>     int x = 0;
>     short y;
> 
>     constexpr foo() = default;
> };

This does compile... but I cannot instantiate a constexpr foo. Adding this
line:

constexpr foo test;

Gives me the following output:

g++-4.7 -std=gnu++11 -o Test.o -c Test.cpp
Test.cpp: In function 'int main(int, char**)':
Test.cpp:35:16: error: uninitialized const 'test' [-fpermissive]
Test.cpp:6:7: note: 'const union foo' has no user-provided default constructor
Test.cpp:11:15: note: constructor is not user-provided because it is explicitly
defaulted in the class body
Test.cpp:9:11: note: and the implicitly-defined constructor does not initialize
'short int foo::y'
Test.cpp:35:16: error: 'constexpr foo::foo()' called in a constant expression
Test.cpp:11:15: note: 'constexpr foo::foo()' is not usable as a constexpr
function because:

Yeah... the last line ends with a colon but no followup. Might want to reopen
this...


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (6 preceding siblings ...)
  2012-02-03  6:24 ` nephatrine at gmail dot com
@ 2012-02-07  1:30 ` jason at gcc dot gnu.org
  2012-02-08  9:53 ` jason at gcc dot gnu.org
  2012-02-08 10:30 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2012-02-07  1:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

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


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (7 preceding siblings ...)
  2012-02-07  1:30 ` jason at gcc dot gnu.org
@ 2012-02-08  9:53 ` jason at gcc dot gnu.org
  2012-02-08 10:30 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2012-02-08  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2012-02-08 09:52:23 UTC ---
Author: jason
Date: Wed Feb  8 09:52:19 2012
New Revision: 184001

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184001
Log:
    PR c++/51675
    * semantics.c (cx_check_missing_mem_inits): Handle unions.
    Fix constexpr default constructor logic.

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


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

* [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
  2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
                   ` (8 preceding siblings ...)
  2012-02-08  9:53 ` jason at gcc dot gnu.org
@ 2012-02-08 10:30 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-02-08 10:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |FIXED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-02-08 10:29:48 UTC ---
Fixed.


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

end of thread, other threads:[~2012-02-08 10:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-24 18:25 [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions classixretrox at gmail dot com
2011-12-24 18:40 ` [Bug c++/51675] " classixretrox at gmail dot com
2011-12-24 22:26 ` [Bug c++/51675] [C++11][4.7 Regression] " paolo.carlini at oracle dot com
2012-01-02  5:41 ` jason at gcc dot gnu.org
2012-01-02 10:51 ` rguenth at gcc dot gnu.org
2012-01-02 17:54 ` jason at gcc dot gnu.org
2012-01-03 16:42 ` paolo.carlini at oracle dot com
2012-02-03  6:24 ` nephatrine at gmail dot com
2012-02-07  1:30 ` jason at gcc dot gnu.org
2012-02-08  9:53 ` jason at gcc dot gnu.org
2012-02-08 10:30 ` jakub 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).