public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: "Andy Falanga (afalanga)" <afalanga@micron.com>,
	       Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: Possible bug in gcc 4.4.7
Date: Wed, 17 Sep 2014 18:05:00 -0000	[thread overview]
Message-ID: <5419CD78.9040703@redhat.com> (raw)
In-Reply-To: <60F6FAE47D1BCE4380CC06D18F49789B93F81CD4@NTXBOIMBX02.micron.com>

On 09/17/2014 06:15 PM, Andy Falanga (afalanga) wrote:

> Ha, nothing except my thinking that, because I was casting a
> reference, I had to use reinterpret_cast<>.  Of course, that (your
> suggestion) worked for me.  Please point me to the correct section
> of the language spec so that I might better understand why this is
> undefined behavior.

Here's the C version:

"6.5 Expressions":

An object shall have its stored value accessed only by an lvalue
expression that has one of the following types:

    a type compatible with the effective type of the object,

    a qualified version of a type compatible with the effective type
    of the object,

    a type that is the signed or unsigned type corresponding to the
    effective type of the object,

    a type that is the signed or unsigned type corresponding to a
    qualified version of the effective type of the object,

    an aggregate or union type that includes one of the aforementioned
    types among its members (including, recursively, a member of a
    subaggregate or contained union), or

    a character type.

C++ uses the same rule.  If you access an object using an lvalue
expression of an incompatible type, all bets are off.

static_cast<Flag>(reinterpret_cast<unsigned int&>(f1) is an example
of such an expression.

Andrew.

  reply	other threads:[~2014-09-17 18:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-17 16:17 Andy Falanga (afalanga)
2014-09-17 17:00 ` Jonathan Wakely
2014-09-17 17:15   ` Andy Falanga (afalanga)
2014-09-17 18:05     ` Andrew Haley [this message]
2014-09-17 20:34       ` Andy Falanga (afalanga)
2014-09-18  0:12         ` Jonathan Wakely
2014-09-18 14:25           ` Andy Falanga (afalanga)
2014-09-18 17:42             ` Jonathan Wakely
2014-09-18 20:40               ` Andy Falanga (afalanga)
2014-09-17 23:57     ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5419CD78.9040703@redhat.com \
    --to=aph@redhat.com \
    --cc=afalanga@micron.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jwakely.gcc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).