------- Comment #10 from rguenth at gcc dot gnu dot org 2006-01-08 10:35 ------- (In reply to comment #9) > Actually that is still a violation of the aliasing rules, as you are acessing > a > character as a Foo. Yes that is violation, though I think GCC does not define > it as one.
I think the code is fine - memory is accessed only as Foo (though it is declared as char). This simulates int foo_charchar(void) { void *i = alloca(2*sizeof(int)); new (i) Foo(); return reinterpret_cast<Foo*>(i)->i[0]; } by making the storage explicit. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19637