Skip to content

[basic.life] Giving less storage is still not UB #982

Description

@languagelawyer

Full name of submitter: Andrey Erokhin

Reference (section label): [basic.life]

Link to reflector thread (if any):

Issue description:

[basic.life]/1:

The lifetime of an object of type T begins when:
— storage with the proper alignment and size for type T is obtained

What about improper alignment and size? For alignment, there is [basic.align]/1:

Attempting to create an object ([intro.object]) in storage that does not meet the alignment requirements of the object's type is undefined behavior ([ub:basic.align.object.alignment]).

However, I couldn't find UB for size, meaning that in

alignas(int) unsigned char c;
auto pi = ::new(&c) int(0); // creates an int object whose lifetime just doesn't start?

Suggested resolution:

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