g++ and aliasing bools
Joe Buck
jbuck@synopsys.COM
Fri Jan 25 13:07:00 GMT 2002
I wrote:
[ attempt at a proof that Daniel's right ]
Mark writes:
> Your proof has at least one bug. A type that has no baseclasses or
> virtuals can contain (as a data member) a type that does; such a type
> is at least as complex as the contained type. (Similarly, an array
> of classes with virtual bases, etc.) You need to recurse through the
> type structure.
Good catch. OK, Daniel, Mark has demonstrated that he was correct in
asking you for a proof: your proposal was wrong.
> It may be that with that change, your sketch is correct -- but the
> fact that you missed this point just makes me more nervous. It
> shows that smart people with long experience with C++ can get tripped
> up here.
My many years of net experience demonstrate that the fastest way to make
progress is often to strongly assert something and wait for someone to
blow it up. At the risk of looking bad twice: if no object at any level
in the aggregate has any virtual functions or baseclasses, it is safe
to apply the C aliasing rules, because for the purpose of aliasing, it
is just C (presence of nonvirtual member functions and protection
change nothing). So, if we have an aggregate, we must (recursively)
check all members.
More information about the Gcc
mailing list