2302. Passing null pointer to placement new

Section: 21.6.2.3 [new.delete.placement] Status: Pending NAD Submitter: Marc Glisse Opened: 2013-09-12 Last modified: 2017-09-10

Priority: 2

View all other issues in [new.delete.placement].

View all issues with Pending NAD status.

Discussion:

Based on this discussion and as discussed in c++std-core-23998 and c++std-lib-34442, calling placement new currently forces the compiler to check if the pointer is null before initializing the object (a non-negligible cost). It seems many people were not aware of this and they consider it a user error to pass a null pointer to it.

Proposed resolution: for operator new and operator new[], add:

Requires: ptr shall not be a null pointer.

[2014-02-15 post-Issaquah session : move to Tentatively NAD]

AJM to supply the rationale...

Proposed resolution:

This wording is relative to N3691.

  1. Change 21.6.2.3 [new.delete.placement] as indicated:

    void* operator new(std::size_t size, void* ptr) noexcept;
    

    -?- Requires: ptr shall not be a null pointer.

    -2- Returns: ptr.

    -3- Remarks: Intentionally performs no other action.

    -4- [Example: This can be useful for constructing an object at a known address:

    void* place = operator new(sizeof(Something));
    Something* p = new (place) Something();
    

    end example]

    void* operator new[](std::size_t size, void* ptr) noexcept;
    

    -?- Requires: ptr shall not be a null pointer.

    -5- Returns: ptr.

    -6- Remarks: Intentionally performs no other action.