- Title
- Placement new with a null pointer
- Status
- cd4
- Section
- 7.6.2.8 [expr.new]
- Submitter
- Marc Glisse
Created on 2013-09-11.00:00:00 last changed 116 months ago
Messages
Date: 2014-11-15.00:00:00
[Moved to DR at the November, 2014 meeting.]
Date: 2014-02-15.00:00:00
Proposed resolution (February, 2014): Change 7.6.2.8 [expr.new] paragraph 15 as follows:
[Note: unless an allocation function is declared with a
non-throwing exception-specification (14.5 [except.spec]), it
indicates failure to allocate storage by throwing a std::bad_alloc
exception (Clause 14 [except], 17.6.4.1 [bad.alloc]);
it returns a non-null pointer otherwise. If the allocation function is
declared with a non-throwing exception-specification, it returns
null to indicate failure to allocate storage and a non-null pointer
otherwise. —end note] If the allocation function is a
reserved placement allocation function (17.6.3.4 [new.delete.placement]) that
returns null, the behavior is undefined. Otherwise, if the allocation
function returns null, initialization shall not be done, the deallocation
function shall not be called, and the value of the new-expression
shall be null.
Date: 2026-07-25.21:52:10
According to 7.6.2.8 [expr.new] paragraph 15, This wording applies even to the non-replaceable placement forms defined
in 17.6.3.4 [new.delete.placement] that simply return the supplied pointer as
the result of the allocation function. Compilers are thus required to
check for a null pointer and avoid the initialization if one is used. This
test is unnecessary overhead; it should be the user's responsibility to
ensure that a null pointer is not used in these forms of placement new,
just as for other cases when a pointer is dereferenced.
[Note: unless an allocation function is declared with a
non-throwing exception-specification (14.5 [except.spec]), it
indicates failure to allocate storage by throwing a std::bad_alloc
exception (Clause 14 [except], 17.6.4.1 [bad.alloc]);
it returns a non-null pointer otherwise. If the allocation function is
declared with a non-throwing exception-specification, it returns
null to indicate failure to allocate storage and a non-null pointer
otherwise. —end note] If the allocation function returns null,
initialization shall not be done, the deallocation function shall not be
called, and the value of the new-expression shall be null.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-02-06 00:00:00 | admin | set | status: drwp -> cd4 |
| 2015-05-25 00:00:00 | admin | set | status: dr -> drwp |
| 2015-04-13 00:00:00 | admin | set | messages: + msg5343 |
| 2014-11-24 00:00:00 | admin | set | status: ready -> dr |
| 2014-03-03 00:00:00 | admin | set | messages: + msg4809 |
| 2014-03-03 00:00:00 | admin | set | status: open -> ready |
| 2013-09-11 00:00:00 | admin | create | |