Title
Passing null pointer to placement new
Status
nad
Section
[new.delete.placement]
Submitter
Marc Glisse

Created on 2013-09-12.00:00:00 last changed 131 months ago

Messages

Date: 2014-03-03.13:52:20

Proposed resolution:

This wording is relative to N3691.

  1. Change [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.

Date: 2014-02-15.00:00:00

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

AJM to supply the rationale...

Date: 2013-09-12.00:00:00

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.

History
Date User Action Args
2014-03-03 13:52:20adminsetmessages: + msg6896
2014-03-03 13:52:20adminsetstatus: new -> nad
2013-10-06 18:38:24adminsetmessages: + msg6674
2013-09-12 00:00:00admincreate