https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283
Steven Sun <StevenSun2021 at hotmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |StevenSun2021 at hotmail dot com --- Comment #1 from Steven Sun <StevenSun2021 at hotmail dot com> --- It is indeed a bug. I currently only investigated into the gcc-12, it generates something for ``` struct S{ /**/ }; bool w; co_yield w ? S{"a"} : S{"b"}; ``` pseudo-code for the generated gimple: ``` char __res[sizeof(S)]; char __a[sizeof(S)]; char __b[sizeof(S)]; new (__a) S("a"); new (__b) S("b"); if (w) memcpy(__res, __a, sizeof(S)); else memcpy(__res, __b, sizeof(S)); /* ... */ __b->~S(); __a->~S(); __c->~S(); ``` So, clearly there is at least 3 bugs here: i. `__res` is never constructed. ii. only one of the `__a` and `__b` should be constructed, not both. iii. the assignment is not corrected (it uses `gimple_assign` for value copy). If the ii is correctly implemented, iii will not happen. Though, the code will work fine on all trivial types. The correct code should be ``` char __res[sizeof(S)]; if (w) new (__res) S("a"); else new (__res) S("b"); /* ... */ __res->~S(); ```