Strict aliasing plus placement new / explicit destructor call
Ian Lance Taylor
iant@google.com
Thu Jul 29 06:46:00 GMT 2010
Justin Lebar <justin.lebar@gmail.com> writes:
> I'm surprised that everyone here is in agreement that the code I
> posted obeys the strict aliasing rules. My understanding -- and
> perhaps this is totally wrong -- is that the "may alias" relation
> isn't transitive. That is, although char* may alias anything, T* may
> not alias char*. Perhaps this explains the error I'm getting.
It's valid because the C++ aliasing rules are not the same as the C
aliasing rules. In C++, if you use placement new, it changes the
dynamic type of the memory location. The memory location must then be
accessed using that type, until a new placement new is run, or the
memory is modified using the original type.
Ian
More information about the Gcc-help
mailing list