Created on 2022-08-27.00:00:00 last changed 27 months ago
Proposed resolution (approved by CWG 2022-10-07):
Change in 6.8.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,- ...
[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.8.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.8.4 [basic.life] bullet 6.2 and 6.8.4 [basic.life] bullet 7.2. The rules ought to be consistent.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2023-07-16 13:00:43 | admin | set | status: open -> c++23 |
| 2023-07-16 13:00:43 | admin | set | status: drwp -> open |
| 2023-02-18 18:43:04 | admin | set | status: dr -> drwp |
| 2022-11-25 05:14:04 | admin | set | status: ready -> dr |
| 2022-10-07 20:29:56 | admin | set | status: open -> ready |
| 2022-09-06 07:05:17 | admin | set | messages: + msg6929 |
| 2022-08-27 00:00:00 | admin | create | |