This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: bug in GCC or C++ standard ?
- From: "Mark Tall" <mtall dot qld at gmail dot com>
- To: "René Bürgel" <r dot buergel at unicontrol dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 12 Nov 2008 21:00:55 +1000
- Subject: Re: bug in GCC or C++ standard ?
- References: <491AAEAE.8090102@unicontrol.de>
On 12/11/2008, René Bürgel <r.buergel@unicontrol.de> wrote:
> If all members of the union are const, why don't you just make the union
> itself const?
The const for the union seems to be ignored (code below). The
original reason behind the union shenanigans was to provide a
compile-time alias to another variable of the same type (due to fusion
of two large legacy code bases into one). It is of course possible to
provide an alias in the form of const int&, however I tried to avoid
the storage penalty.
struct my_class_3
{
const union
{
int x;
int y;
};
my_class_3() : x(0) {}
};
int main(int argc, char** argv)
{
my_class_3 abc;
abc.y = 5;
std::cout << abc.x << std::endl;
return 0;
}
output:
5