<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2458: N3778 and new library deallocation signatures</title>
<meta property="og:title" content="Issue 2458: N3778 and new library deallocation signatures">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2458.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2458"><a href="lwg-defects.html#2458">2458</a>. N3778 and new library deallocation signatures</h3>
<p><b>Section:</b> 17.6 <a href="https://wg21.link/support.dynamic">[support.dynamic]</a>, 17.6.3.2 <a href="https://wg21.link/new.delete.single">[new.delete.single]</a>, 17.6.3.3 <a href="https://wg21.link/new.delete.array">[new.delete.array]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2014-11-23 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#support.dynamic">issues</a> in [support.dynamic].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3778.html">N3778</a> 
added the following sized deallocation signatures to the library:
</p>
<blockquote><pre>
void operator delete(void* ptr, std::size_t size) noexcept;
void operator delete[](void* ptr, std::size_t size) noexcept;

void operator delete(void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept;
void operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept;
</pre></blockquote>
<p>
The former two are an essential part of the proposal. The latter two seem
spurious &mdash; they are not called when <code>new (std::nothrow) X</code> fails due to
<code>X::X()</code> throwing, because the core language rules for selecting a placement
deallocation function do not consider passing a <code>size</code> argument. Instead, the
above would be the matching deallocation functions for:
</p>
<blockquote><pre>
void *operator new(std::size_t size, std::size_t size_again, const std::nothrow_t&amp;) noexcept;
void *operator new[](std::size_t size, std::size_t size_again, const std::nothrow_t&amp;) noexcept;
</pre></blockquote>
<p>
... which don't exist.
<p/>
Since they're not implicitly called, the only other possible use for those
functions would be to perform an explicitly non-throwing deallocation.
But... the first two overloads are already explicitly non-throwing and are
required to be semantically identical to the second two. So there's no
point in making an explicit call to the second pair of functions either.
<p/>
It seems to me that we should remove the <code>(void*, size_t, nothrow_t)</code> overloads, because
the core working group decided during the Urbana 2014 meeting, that no change to the core 
language was warranted.
</p>

<p><i>[2014-11-23, Daniel suggests concrete wording changes]</i></p>


<p><i>[2015-02 Cologne]</i></p>

<p>
Nobody can call those overloads, since the nothrow allocation functions cannot throw. JY: Ship it. GR: Should we do due 
diligence and make sure we're deleting what we mean to be deleting? [Some checking, everything looks good.]
<p/>
Accepted.
</p>


<p id="res-2458"><b>Proposed resolution:</b></p>
<p>This wording is relative to N4140.</p>

<ol>
<li><p>Change 17.6 <a href="https://wg21.link/support.dynamic">[support.dynamic]</a>, header <code>&lt;new&gt;</code> synopsis, as indicated:</p>

<blockquote><pre>
[&hellip;]
void operator delete(void* ptr, std::size_t size) noexcept;
<del>void operator delete(void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept;</del>
[&hellip;]
void operator delete[](void* ptr, std::size_t size) noexcept;
<del>void operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept;</del>
[&hellip;]
</pre></blockquote>

</li>

<li><p>Change 17.6.3.2 <a href="https://wg21.link/new.delete.single">[new.delete.single]</a>, starting before p19, as indicated:</p>
<blockquote><pre>
void operator delete(void* ptr, const std::nothrow_t&amp;) noexcept;
<del>void operator delete(void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept;</del>
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-20- <i>Replaceable</i>: a C++ program may define a function with signature <code>void operator delete(void*
ptr, const std::nothrow_t&amp;) noexcept</code> that displaces the default version defined by the C++ standard
library. <del>If this function (without <code>size</code> parameter) is defined, the program should also define
<code>void operator delete(void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept</code>. If
this function with <code>size</code> parameter is defined, the program shall also define the version without the
<code>size</code> parameter. [<i>Note</i>: The default behavior below may change in the future, which will require
replacing both deallocation functions when replacing the allocation function. &mdash; <i>end note</i>]</del>
<p/>
[&hellip;]
<p/>
<del>-22- <i>Requires</i>: If present, the <code>std::size_t size</code> argument must equal the <code>size</code> 
argument passed to the allocation function that returned <code>ptr</code>.</del>
<p/>
<del>-23- <i>Required behavior</i>: Calls to <code>operator delete(void* ptr, std::size_t size, const std::nothrow_t&amp;)</code> 
may be changed to calls to <code>operator delete(void* ptr, const std::nothrow_t&amp;)</code> without affecting
memory allocation. [<i>Note</i>: A conforming implementation is for <code>operator delete(void* ptr, std::size_t size, 
const std::nothrow_t&amp;)</code> to simply call <code>operator delete(void* ptr, const std::nothrow_t&amp;)</code>. &mdash; 
<i>end note</i>]</del>
<p/>
-24- <i>Default behavior</i>: <del><code>operator delete(void* ptr, std::size_t size, const std::nothrow_t&amp;)</code> 
calls <code>operator delete(ptr, std::nothrow)</code>, and</del> <code>operator delete(void* ptr, const std::nothrow_t&amp;)</code> 
calls <code>operator delete(ptr)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Change 17.6.3.3 <a href="https://wg21.link/new.delete.array">[new.delete.array]</a>, starting before p16, as indicated:</p>
<blockquote><pre>
void operator delete[](void* ptr, const std::nothrow_t&amp;) noexcept;
<del>void operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept;</del>
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-17- <i>Replaceable</i>: a C++ program may define a function with signature <code>void operator delete[](void*
ptr, const std::nothrow_t&amp;) noexcept</code> that displaces the default version defined by the C++ standard
library. <del>If this function (without <code>size</code> parameter) is defined, the program should also define <code>void
operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;) noexcept</code>. If this
function with <code>size</code> parameter is defined, the program shall also define the version without the <code>size</code>
parameter. [<i>Note</i>: The default behavior below may change in the future, which will require replacing
both deallocation functions when replacing the allocation function. &mdash; <i>end note</i>]</del>
<p/>
[&hellip;]
<p/>
<del>-19- <i>Requires</i>: If present, the <code>std::size_t size</code> argument must equal the <code>size</code> argument 
passed to the allocation function that returned <code>ptr</code>.</del> 
<p/>
<del>-20- <i>Required behavior</i>: Calls to <code>operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;)</code> 
may be changed to calls to <code>operator delete[](void* ptr, const std::nothrow_t&amp;)</code> without affecting memory allocation. 
[<i>Note</i>: A conforming implementation is for <code>operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;)</code> 
to simply call <code>operator delete[](void* ptr, const std::nothrow_t&amp;)</code>. &mdash; <i>end note</i>]</del>
<p/>
-21- <i>Default behavior</i>: <del><code>operator delete[](void* ptr, std::size_t size, const std::nothrow_t&amp;)</code>
calls <code>operator delete[](ptr, std::nothrow)</code>, and</del> <code>operator delete[](void* ptr, const std::nothrow_t&amp;)</code> 
calls <code>operator delete[](ptr)</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
