This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions
- From: "classixretrox at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 24 Dec 2011 18:23:37 +0000
- Subject: [Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions
- Auto-submitted: auto-generated
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.