Skip to content

[basic.life] CWG2625 broke dynamic arrays providing storage #415

@languagelawyer

Description

@languagelawyer

Full name of submitter: JMC

Reference (section label): [basic.life]

Link to reflector thread (if any): https://stackoverflow.com/questions/77023929/c23-changes-disallow-using-dynamically-allocated-array-as-storage-provider

Issue description:
CWG2625 did to [basic.life]/6.1:

… after the lifetime of an object has ended … 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,

now consider

auto buf = new unsigned char[sizeof(int)];
new (buf) int; // kills buf[0]
delete[] buf; // the pointer to buf[0] is used as the operand of delete-expression

Suggested resolution:
Undo CWG2625 resolution. Or, at least, limit the restriction to single-object delete expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions