This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
bug in GCC or C++ standard ?
- From: "Mark Tall" <mtall dot qld at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 12 Nov 2008 12:53:54 +1000
- Subject: bug in GCC or C++ standard ?
Hello,
I've come across an oddity in C++, involving anonymous unions and
const variables. Neither of the two classes below will compile using
gcc 4.3.0. Is this a bug in gcc or the C++ standard itself ?
class my_class_1
{
union
{
const int x;
const int y;
};
my_class_1() : x(0), y(0) {}
};
class my_class_2
{
union
{
const int x;
const int y;
};
my_class_2() : x(0) {}
};
compiler output:
my_class.cpp: In constructor 'my_class_1::my_class_1()':
my_class.cpp:10: error: initializations for multiple members of
'my_class_1::<anonymous union>'
my_class.cpp: In constructor 'my_class_2::my_class_2()':
my_class.cpp:22: error: uninitialized member 'my_class_2::<anonymous
union>::y' with 'const' type 'const int'