C++ aliasing rules
Jason Merrill
jason@redhat.com
Tue Apr 23 13:52:00 GMT 2002
>>>>> "Dan" == Dan Nicolaescu <dann@godzilla.ICS.UCI.EDU> writes:
> struct first { int i; char a; int f1; char f2; double d;};
> struct second { char b; int f2; int f3;};
> can it be assumed that given that "first" and "second" are
> incompatible then ps1.f1 and ps2.f2 don't alias
I'm not sure. I suppose it depends on whether you consider ps1.f1 to be an
object for the purposes of [basic.lval], which says that an object can be
referenced through an lvalue of a class type which contains a member of
that object's type. So since ps1.f1 is an int, and struct second contains
an int, the access can alias.
If we think that [basic.lval] only means to talk about complete objects,
then the access can't alias.
I'm not sure what the intent is, but from a strict reading I tend towards
the first interpretation; according to [intro.object] sub-objects are
objects, too.
Jason
More information about the Libstdc++
mailing list