Created on 2023-07-17.00:00:00 last changed 1 month ago
Possible resolution:
Change in 6.8.4 [basic.life] paragraph 12 as follows:
Creating a new object O within the storage that a const, complete object X with static, thread, or automatic storage duration occupies, or within the storage that such a const object used to occupy before its lifetime ended, results in undefined behavior unless O is nested within a mutable subobject of X. [ Example: ... ]
(From submission #367.)
Consider:
struct S {
alignas(int) mutable unsigned char buf[sizeof(int)];
};
int f() {
const S s{};
::new ((void*)s.buf) int{42};
}
Creating a new object in the mutable portion of a const complete object is undefined behavior per 6.8.4 [basic.life] paragraph 12. However, this ought to be allowed.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-11-06 23:04:52 | admin | set | messages: + msg8340 |
| 2023-07-17 00:00:00 | admin | create | |