#include struct S1 { char a[2]; char b[2]; char c[2]; S1 () { a[0] = 0; b[0] = 0; c[0] = 0; }; ~S1 () {} }; struct S2 { char d[6]; S2 () { d[0] = 0; d[2] = 0; } ~S2 () {} }; __attribute__((noipa)) void foo (char *b) { b[0] = 1; b[1] = 2; asm volatile ("" : : "g" (b) : "memory"); } __attribute__((noipa)) void bar (char *d) { __builtin_memcpy (d, "cde", 4); asm volatile ("" : : "g" (d) : "memory"); } __attribute__((noipa)) void baz (char *buf) { S1 *s1 = new (buf) S1 (); char *p = (char *) &s1->b; foo (p); s1->~S1 (); S2 *s2 = new (buf) S2 (); char *q = (char *) &s2->d[2]; bar (q); if (__builtin_strcmp (q, "cde")) __builtin_abort (); s2->~S2 (); } int main () { char buf[sizeof (S1) > sizeof (S2) ? sizeof (S1) : sizeof (S2)]; baz (buf); return 0; }