This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
- From: "nephatrine at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 03 Feb 2012 06:24:12 +0000
- Subject: [Bug c++/51675] [C++11][4.7 Regression] Cannot create constexpr unions
- Auto-submitted: auto-generated
- References: <bug-51675-4@http.gcc.gnu.org/bugzilla/>
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...