<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2207</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="2207"></A><H4>2207.
  
Alignment of allocation function return value
</H4>
<B>Section: </B>6.8.6.5.2&#160; [<A href="https://wg21.link/basic.stc.dynamic.allocation">basic.stc.dynamic.allocation</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD5
 &#160;&#160;&#160;

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2015-12-02<BR>


<P>[Accepted as a DR at the July, 2019 meeting.]</P>



<P>According to 6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation#2">basic.stc.dynamic.allocation</A>] paragraph 2,</P>

<BLOCKQUOTE>

For an allocation function other than a reserved placement allocation
function (17.6.3.4 [<A href="https://wg21.link/new.delete.placement">new.delete.placement</A>]), the pointer returned is suitably
aligned so that it can be converted to a pointer to any suitable complete
object type (17.6.3.2 [<A href="https://wg21.link/new.delete.single">new.delete.single</A>]) and then used to access the
object or array in the storage allocated (until the storage is explicitly
deallocated by a call to a corresponding deallocation function).

</BLOCKQUOTE>

<P>This requirement seems excessive, as it appears to require
the strictest fundamental alignment even for objects that are
too small to require such an alignment.</P>

<P><B>Proposed resolution (March, 2019):</B></P>

<OL>
<LI><P>Change 6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation#2">basic.stc.dynamic.allocation</A>] paragraph 2 as
follows:</P></LI>

<BLOCKQUOTE>

...The order, contiguity, and initial value of storage
allocated by successive calls to an allocation function are
unspecified. <DEL>For an allocation function other than a
reserved placement allocation function
(17.6.3.4 [<A href="https://wg21.link/new.delete.placement">new.delete.placement</A>]), the pointer returned is
suitably aligned so that it can be converted to a pointer to
any suitable complete object type
(17.6.3.2 [<A href="https://wg21.link/new.delete.single">new.delete.single</A>]) and then used to access the
object or array in the storage allocated (until the storage
is explicitly deallocated by a call to a corresponding
deallocation function).</DEL> Even if the size of the space
requested...

</BLOCKQUOTE>

<LI><P>Add the following as a new paragraph to
6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation">basic.stc.dynamic.allocation</A>] after the existing paragraph 2:</P></LI>

<BLOCKQUOTE>
<P><INS>For an allocation function other than a
reserved placement allocation function
(17.6.3.4 [<A href="https://wg21.link/new.delete.placement">new.delete.placement</A>]), the pointer returned on a
successful call shall represent the address of storage that
is aligned as follows:</INS></P>

<UL>
<LI><P><INS>If the allocation function takes an argument
of type <TT>std::align_val_t</TT>, then the storage will
have the alignment specified by the value of this
argument.</INS></P></LI>

<LI><P><INS>Otherwise, if the allocation function is
named <TT>operator new[]</TT>, then the storage is aligned
for any object that does not have new-extended alignment
(6.8.3 [<A href="https://wg21.link/basic.align">basic.align</A>]) and is no larger than the
requested size.</INS></P></LI>

<LI><P><INS>Otherwise, the storage is aligned for any object that does not have new-extended alignment and is of the requested size.</INS></P></LI>

</UL>

</BLOCKQUOTE>

<LI><P>Change 17.6.3.2 [<A href="https://wg21.link/new.delete.single#1">new.delete.single</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

<I>Effects:</I> The allocation functions
(6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation">basic.stc.dynamic.allocation</A>]) called by
a <I>new-expression</I> (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]) to
allocate <TT>size</TT> bytes of storage. The second form is
called for a type with new-extended alignment,
and <DEL>allocates storage with the specified
alignment. The</DEL> <INS>the</INS> first form is called
otherwise<DEL>, and allocates storage suitably aligned to
represent any object of that size provided the object's type
does not have new-extended alignment</DEL>.

</BLOCKQUOTE>

<LI><P>Change 17.6.3.3 [<A href="https://wg21.link/new.delete.array#1">new.delete.array</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

<I>Effects:</I> The allocation functions
(6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation">basic.stc.dynamic.allocation</A>]) called by the array form of
a <I>new-expression</I> (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]) to
allocate <TT>size</TT> bytes of storage. The second form is
called for a type with new-extended alignment, and <DEL>allocates
storage with the specified alignment. The</DEL>
<INS>the</INS> first form is called otherwise<DEL>, and
allocates storage suitably aligned to represent any array
object of that size or smaller, provided the object's type
does not have new-extended alignment</DEL>.<SUP>218</SUP>

</BLOCKQUOTE>

</OL>

<BR><BR>
</BODY>
</HTML>
