<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2843: Unclear behavior of std::pmr::memory_resource::do_allocate()</title>
<meta property="og:title" content="Issue 2843: Unclear behavior of std::pmr::memory_resource::do_allocate()">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2843.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++20">C++20</a> status.</em></p>
<h3 id="2843"><a href="lwg-defects.html#2843">2843</a>. Unclear behavior of <code>std::pmr::memory_resource::do_allocate()</code></h3>
<p><b>Section:</b> 20.5.2.3 <a href="https://wg21.link/mem.res.private">[mem.res.private]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Jens Maurer <b>Opened:</b> 2016-12-13 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#mem.res.private">issues</a> in [mem.res.private].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The specification of <code>do_allocate()</code> (20.5.2.3 <a href="https://wg21.link/mem.res.private">[mem.res.private]</a> p2+p3) says:
</p>
<blockquote>
<p>
<i>Returns:</i> A derived class shall implement this function to return a
pointer to allocated storage (3.7.4.2) with a size of at least <code>bytes</code>.
The returned storage is aligned to the specified alignment, if such
alignment is supported (3.11); otherwise it is aligned to <code>max_align</code>.
<p/>
<i>Throws:</i> A derived class implementation shall throw an appropriate
exception if it is unable to allocate memory with the requested size
and alignment.
</p>
</blockquote>
<p>
It is unclear whether a request for an unsupported alignment
(e.g. larger than <code>max_align</code>) yields an exception or the returned
storage is silently aligned to <code>max_align</code>.
<p/>
This is <a href="https://github.com/cplusplus/draft/issues/966">editorial issue #966</a>.
</p>

<p><i>[2017-01-27 Telecon]</i></p>

<p>Priority 3; Marshall to ping Pablo for intent and provide wording.</p>

<p><i>[2017-02-12 Pablo responds and provides wording]</i></p>

<p>The original intent was:</p>
<ul>
  <li>If the alignment is supported by the implementation (see below), then it must use that alignment or else throw.</li>
  <li>If the alignment is not supported it must use max_align else throw.</li>
</ul>
<p>However, the description of do_allocate might have gone stale as the
aligned-allocation proposal made its way into the standard.</p>

<p>The understanding I take from the definition of extended alignment in
(the current text of) 3.11/3 [basic.align] and "assembling an argument
list" in 5.3.4/14 [expr.new] is that it is intended that, when
allocating space for an object with extended alignment in a well-formed
program, the alignment <i>will</i> be honored and <i>will not be</i>
truncated to max_align. I think this is a change from earlier drafts of
the extended-alignment proposal, where silent truncation to <code>max_align</code>
was permitted (I could be wrong). Anyway, it seems wrong to ever ignore
the alignment parameter in <code>do_allocate()</code>.</p>

<p><i>[2017-11 Albuquerque Wednesday issue processing]</i></p>

<p>Move to Ready.</p>
<p><i>[2018-3-17 Adopted in Jacksonville]</i></p>



<p id="res-2843"><b>Proposed resolution:</b></p>
<p>Change the specification of <code>do_allocate()</code> (20.5.2.3 <a href="https://wg21.link/mem.res.private">[mem.res.private]</a> p2+p3) as follows:</p>

<blockquote>
  <p><i>Returns</i>: A derived class shall implement this function to
  return a pointer to allocated storage (3.7.4.2) with a size of at
  least <code>bytes</code><ins>, aligned to the specified
  <code>alignment</code></ins>. <del>The returned storage is aligned to the
  specified alignment, if such alignment is supported; otherwise it is
  aligned to <code>max_align</code>.</del></p>

<p><i>Throws:</i> A derived class implementation shall throw an
appropriate exception if it is unable to allocate memory with the
requested size and alignment.</p>
</blockquote>





</body>
</html>
