Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated for get_temporary_buffer()

...

AllocatorDeallocator
operator new()/newoperator delete()/delete
operator new[]()/new[]operator delete[]()/delete[]
placement operator new()N/A
allocator<T>::allocate()

allocator<T>::deallocate()

std::malloc(), std::calloc(),
std::realloc()
std::free()
std::get_temporary_buffer()std::return_temporary_buffer()
Page properties
hiddentrue

While the wording for std::return_temporary_buffer() in C++14 does not imply that you can pass a null pointer to it, that wording is superseded by the resolution for LWG 2072 (http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2072) which does allow for null to be passed. Looking at all of the major implementations that I can get my hands on (MSVC STL, libc++, libstdc++, and stdcxx), it appears they all safely handle null pointer inputs as of 06/2015.

Passing a pointer value to an inappropriate deallocation function can result in undefined behavior.

...

[Dowd 2007]"Attacking delete and delete [] in C++"
[Henricson 1997]Rule 8.1, delete should only be used with new
Rule 8.2, delete [] should only be used with new []
[ISO/IEC 14882-2014]

Subclause 5.3.5, "Delete"
Subclause 12.8, "Copying and Moving Class Objects"
Subclause 18.6.1, "Storage Allocation and Deallocation"
Subclause 20.7.11, "Temporary Buffers" 

[Meyers 2005]Item 16, "Use the Same Form in Corresponding Uses of new and delete"
[Seacord 2013b]Chapter 4, "Dynamic Memory Management"
[Viega 05]"Doubly Freeing Memory"

...