Skip to content

[basic.life] p2 Creating an object in the part of the storage region occupied by another object is considered to reuse the storage? #885

@xmh0511

Description

@xmh0511

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[basic.life] p2 says:

The lifetime of an object o of type T ends when:

  • [...]
  • the storage which the object occupies is released, or is reused by an object that is not nested within o ([intro.object]).

Consider this example:

alignas(int) unsigned char buffer[8];

int main() {
    auto ptr = new (buffer) int{}; // #1
    new (buffer) char{}; // #2
}

Assuming sizeof(int)==4, #1 starts the lifetime of an object of type int that occupies the storage with 4 bytes. However, #2 uses a part of the storage region, which only uses the head byte. Is the whole 4-byte storage considered to be reused?

Suggested Resolution:

Maybe we need to say that a storage is considered to be reused if any part of the storage is reused.

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