https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107115
Gabriel Ravier <gabravier at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |gabravier at gmail dot com --- Comment #13 from Gabriel Ravier <gabravier at gmail dot com> --- Idk if it qualifies as the same bug or if this will prove to bee particularly useful, but just to make sure the corresponding issue in C++, triggered by this slightly altered code (so that it hopefully respects the stricter rules C++ has w.r.t. implicit object creation) which also fails to execute correctly on GCC, is fixed by the fix to this issue, I'll post here the corresponding code: #include <new> #include <stdio.h> #include <stdlib.h> 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 *)p4, index1, index2); return test3((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); }