http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54922
Bug #: 54922
Summary: [C++11][DR 1359] constexpr constructors require
initialization of all union members
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
gcc 4.8.0 20120930 (experimental) compiled with the flags
-Wall -pedantic -std=c++11
rejects the following code:
//----------------
lass nullable_int
{
bool init_;
union {
unsigned char for_value_init;
int value_;
};
public:
constexpr nullable_int() : init_(false), for_value_init() {}
};
//----------------
"main.cpp||In constructor 'constexpr nullable_int::nullable_int()':|
main.cpp|9|error: uninitialized member 'nullable_int::<anonymous>' in
'constexpr' constructor|"
This prevents a very reasonable use-case, namely the creation of a literal type
that contains an anonymous union member.