This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Possible bug in gcc 4.4.7
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "Andy Falanga (afalanga)" <afalanga at micron dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 17 Sep 2014 18:00:50 +0100
- Subject: Re: Possible bug in gcc 4.4.7
- Authentication-results: sourceware.org; auth=none
- References: <60F6FAE47D1BCE4380CC06D18F49789B93F81C6E at NTXBOIMBX02 dot micron dot com>
On 17 September 2014 17:16, Andy Falanga (afalanga) wrote:
> Flag operator &=(Flag& f1, Flag f2) {
> return static_cast<Flag>(reinterpret_cast<unsigned int&>(f1) &= static_cast<unsigned int>(f2));
> }
That reinterpret_cast looks dodgy to me, accessing the object through
a different type is undefined behaviour. What's wrong with doing it
safely?
Flag operator &=(Flag& f1, Flag f2) {
unsigned int i = f1;
i &= static_cast<unsigned int>(f2);
return f1 = static_cast<Flag>(i);
}