https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107115
--- Comment #14 from Gabriel Ravier <gabravier at gmail dot com> --- Actually I think there's some aliasing violations in the C++ code w.r.t. the re-usage of `p4` after another object has been created in its place so I think this code would be more correct: void test1(long *p1) { p1 = (long *)new ((char*)p1) char[sizeof(long)]; p1[0] = 1; } long test2(long long *p2, int index1, int index2) { p2 = (long long *)new ((char*)p2) char[sizeof(long long)]; p2[index1] = 2; return p2[index2]; } long test3(long *p3, int index2, long value) { p3 = (long *)new ((char*)p3) char[sizeof(long)]; p3[index2] = 3; p3[index2] = value; return p3[0]; } long test4(void *p4, int index1, int index2) { test1((long *)p4); long temp = test2((long long *)std::launder((long *)p4), index1, index2); return test3((long *)std::launder((long long *)p4), index2, temp); } long (*volatile vtest)(void *, int, int) = test4; int main(void) { void *pp = malloc(sizeof(long long)); if (!pp) abort(); long result = vtest(pp, 0, 0); printf("%lu/%lu\n", *std::launder((long *)pp), result); }