[Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions
classixretrox at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 24 18:25:00 GMT 2011
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.
More information about the Gcc-bugs
mailing list