This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-12-19
[Accepted as a DR at the November, 2022 meeting.]
Consider:
struct S {}; int main() { S* p = new S; p->~S(); delete p; }
This code appears to be allowed per 6.7.4 [basic.life] bullet 6.1:
The program has undefined behavior if:
- the object will be or was of a class type with a non-trivial destructor and the pointer is used as the operand of a delete-expression,
- ...
However, this calls the (trivial) destructor on *p twice. Invoking a non-static member function of an out-of-lifetime object is generally undefined behavior per 6.7.4 [basic.life] bullet 6.2 and 6.7.4 [basic.life] bullet 7.2. The rules ought to be consistent.
Proposed resolution (approved by CWG 2022-10-07):
Change in 6.7.4 [basic.life] bullet 6.1 as follows:
The program has undefined behavior if:
the object will be or was of a class type with a non-trivial destructor andthe pointer is used as the operand of a delete-expression,- ...