Skip to content

[basic.life] It is unclear whether destroying an already destroyed scalar object is undefined behavior #361

Open
@frederick-vs-ja

Description

@frederick-vs-ja

Full name of submitter (unless configured in github; will be published with the issue): Géry Ogam (cplusplus/draft#4944)

Reference (section label): [basic.life], [basic.start.term], [expr.prim.id.dtor], [expr.delete]

Link to reflector thread (if any):

Issue description:
P0593R6 made pseudo-destructor calls end lifetime of scalar objects. However, currently there lacks wording indicating that destroying an already destroyed scalar object is undefined behavior, which is inconsistent with class objects.

Currently, implementations tend to accept such double destruction in constant evaluation (Godbolt link). Note that Clang is inconsistent with itself, which seems to be a bug.

using I = int;
constexpr I x = (I{}.~I(), 0); // clang, gcc, and msvc accept this
constexpr I y = ((0).~I(), 0); // clang only rejects this

On the other hand, it is arguably better to keep and clarify the status quo, which avoids inceasing UB.

Suggested resolution:
The changes in cplusplus/draft#4953, if it is intented to make such double destruction undefined.

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