From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24968 invoked by alias); 18 Sep 2014 17:42:21 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 24948 invoked by uid 89); 18 Sep 2014 17:42:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-lb0-f173.google.com Received: from mail-lb0-f173.google.com (HELO mail-lb0-f173.google.com) (209.85.217.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 18 Sep 2014 17:42:19 +0000 Received: by mail-lb0-f173.google.com with SMTP id w7so1651936lbi.18 for ; Thu, 18 Sep 2014 10:42:16 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.152.20.132 with SMTP id n4mr1308730lae.86.1411062136415; Thu, 18 Sep 2014 10:42:16 -0700 (PDT) Received: by 10.112.142.7 with HTTP; Thu, 18 Sep 2014 10:42:16 -0700 (PDT) In-Reply-To: <60F6FAE47D1BCE4380CC06D18F49789B93F82F72@NTXBOIMBX02.micron.com> References: <60F6FAE47D1BCE4380CC06D18F49789B93F81C6E@NTXBOIMBX02.micron.com> <60F6FAE47D1BCE4380CC06D18F49789B93F81CD4@NTXBOIMBX02.micron.com> <5419CD78.9040703@redhat.com> <60F6FAE47D1BCE4380CC06D18F49789B93F81D6D@NTXBOIMBX02.micron.com> <60F6FAE47D1BCE4380CC06D18F49789B93F82F72@NTXBOIMBX02.micron.com> Date: Thu, 18 Sep 2014 17:42:00 -0000 Message-ID: Subject: Re: Possible bug in gcc 4.4.7 From: Jonathan Wakely To: "Andy Falanga (afalanga)" Cc: Andrew Haley , "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-09/txt/msg00110.txt.bz2 On 18 September 2014 15:24, Andy Falanga (afalanga) wrote: >> -----Original Message----- >> From: Jonathan Wakely [mailto:jwakely.gcc@gmail.com] >> Sent: Wednesday, September 17, 2014 6:13 PM >> To: Andy Falanga (afalanga) >> Cc: Andrew Haley; gcc-help@gcc.gnu.org >> Subject: Re: Possible bug in gcc 4.4.7 >> >> On 17 September 2014 21:34, Andy Falanga (afalanga) wrote: >> > Thank you for the reference. I'm going to have to think on this for >> a bit. I read a bit of the definition for reinterpret_cast in the C++ >> Draft I have too. I want to figure this out for sure. >> >> I think you're barking up the wrong tree if you're trying to understand >> when reinterpret_cast is suitable ... because it is almost never a good >> idea! reinterpret_cast basically means "just shut up and do this cast, >> I know what I'm doing", but that means you've lost the advantages of >> having the compiler do type checking. > > Thank you for the warning. In this case, I'm not trying to understand when to violate the rules but, rather, to understand why what I did resulted in undefined behavior. So looking into reinterpret_cast is not very relevant. You are using a reference of type unsigned int& to access something that is not an unsigned int, that's the problem. The fact you used reinterpret_cast to create the reference is not relevant, it's what you did with the reference after you created it that is the problem. This is undefined in the same way, but doesn't use reinterpret_cast: Flag f1; void* vp = &f1; *static_cast(vp) = 1;