http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49803
Summary: [C++0x] erroneous variant-member initialization in a
union containing an anonymous struct
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
/* The output of this code should be 'Y'. But define SHOW_BUG and it becomes
X: */
#define SHOW_BUG
#include <cstdio>
struct X
{
X() : m_value {'X'} {}
char m_value;
};
union Y
{
// N3291=11-0061 12.6.2/8 says no initialization of
// of other variant members (i.e. m_x) should
// be performed.
Y( char c )
: m_char1{ c }
{ }
#ifdef SHOW_BUG
struct
{
#endif
char m_char1;
#ifdef SHOW_BUG
};
#endif
X m_x;
};
int main()
{
Y y ( 'Y' );
printf( "%c\n", y.m_char1 ); // expected 'Y', get 'X'...
return 0;
}