<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2597</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="2597"></A><H4>2597.
  
Replaceable allocation and deallocation functions in the global module
</H4>
<B>Section: </B>10.1&#160; [<A href="https://wg21.link/module.unit">module.unit</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Gabriel dos Reis
 &#160;&#160;&#160;

 <B>Date: </B>2022-06-17
  &#160;&#160;&#160;
  <B>Liaison: </B>EWG<BR>


<P>[Accepted at the July, 2022 meeting.]</P>



<P>Subclause 10.1 [<A href="https://wg21.link/module.unit#7">module.unit</A>] paragraph 7 implicitly attaches
the replaceable global allocation or deallocation functions to the global
module.  Now that <TT>extern "C++"</TT> can be used to introduce
declarations in the global module, even when in the purview of a named
module, the provision seems superfluous.</P>

<P><B>Proposed resolution [SUPERSEDED]:</B></P>

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

<BLOCKQUOTE>

The library provides default definitions for the global allocation and
deallocation functions. Some global allocation and deallocation
functions are replaceable (17.6.3 [<A href="https://wg21.link/new.delete">new.delete</A>]). A C++ program
shall provide at most one definition of a replaceable allocation or
deallocation function. Any such function definition replaces the
default version provided in the library
(16.4.5.6 [<A href="https://wg21.link/replacement.functions">replacement.functions</A>]). The following allocation and
deallocation functions (17.6 [<A href="https://wg21.link/support.dynamic">support.dynamic</A>]) are implicitly
declared in global scope in each translation unit of a
program <INS>and are attached to the global module
(10.1 [<A href="https://wg21.link/module.unit">module.unit</A>])</INS>.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 10.1 [<A href="https://wg21.link/module.unit#7.2">module.unit</A>] bullet 7.2 as follows:</P>

<BLOCKQUOTE>

<UL>
<LI>If the declaration is ...</LI>

<LI>Otherwise, if the declaration
<UL>
<LI>
<DEL>is a replaceable global allocation or deallocation function
(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>]), or</DEL>
</LI>

<LI>is a <I>namespace-definition</I> with external linkage<DEL>,</DEL> or
</LI>

<LI>appears within a <I>linkage-specification</I>
<INS>(9.12 [<A href="https://wg21.link/dcl.link">dcl.link</A>])</INS><DEL>,</DEL>
</LI>
</UL>
it is attached
to the global module.
</LI>

<LI>Otherwise, ...</LI>
</UL>

</BLOCKQUOTE>

</LI>
</OL>

<P><B>Additional notes (June, 2022):</B></P>
<P>Forwarded to EWG with
<A HREF="https://github.com/cplusplus/papers/issues/1273">paper issue 1273</A>,
by decision of the CWG chair.
</P>

<P><B>Approved by EWG telecon 2022-07-07.</B></P>

<P><B>Proposed resolution (approved by CWG 2022-07-15):</B></P>

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

<BLOCKQUOTE>

The library provides default definitions for the global allocation and
deallocation functions. Some global allocation and deallocation
functions are replaceable (17.6.3 [<A href="https://wg21.link/new.delete">new.delete</A>])
<INS>; these are attached to the global module 10.1 [<A href="https://wg21.link/module.unit">module.unit</A>])</INS>.
A C++ program
shall provide at most one definition of a replaceable allocation or
deallocation function. Any such function definition replaces the
default version provided in the library
(16.4.5.6 [<A href="https://wg21.link/replacement.functions">replacement.functions</A>]). The following allocation and
deallocation functions (17.6 [<A href="https://wg21.link/support.dynamic">support.dynamic</A>]) are implicitly
declared in global scope in each translation unit of a
program.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 10.1 [<A href="https://wg21.link/module.unit#7.2">module.unit</A>] bullet 7.2 as follows:</P>

<BLOCKQUOTE>

<UL>
<LI>If the declaration is ...</LI>

<LI>Otherwise, if the declaration
<UL>
<LI>
<DEL>is a replaceable global allocation or deallocation function
(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>]), or</DEL>
</LI>

<LI>is a <I>namespace-definition</I> with external linkage<DEL>,</DEL> or
</LI>

<LI>appears within a <I>linkage-specification</I>
<INS>(9.12 [<A href="https://wg21.link/dcl.link">dcl.link</A>])</INS><DEL>,</DEL>
</LI>
</UL>
it is attached
to the global module.
</LI>

<LI>Otherwise, ...</LI>
</UL>

</BLOCKQUOTE>

</LI>
</OL>

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