<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2020</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="2020"></A><H4>2020.
  
Inadequate description of odr-use of implicitly-invoked functions
</H4>
<B>Section: </B>6.3&#160; [<A href="https://wg21.link/basic.def.odr">basic.def.odr</A>]
 &#160;&#160;&#160;

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

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

 <B>Date: </B>2014-10-08<BR>


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

<P>According to 6.3 [<A href="https://wg21.link/basic.def.odr#3">basic.def.odr</A>] paragraph 3,</P>

<BLOCKQUOTE>

A function whose name appears as a potentially-evaluated
expression is odr-used if it is the unique lookup result or
the selected member of a set of overloaded functions
(6.5 [<A href="https://wg21.link/basic.lookup">basic.lookup</A>], 12.2 [<A href="https://wg21.link/over.match">over.match</A>],
12.3 [<A href="https://wg21.link/over.over">over.over</A>]), unless it is a pure virtual
function and its name is not explicitly
qualified. [<I>Note:</I> This covers calls to named
functions (7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>]), operator overloading
(Clause 12 [<A href="https://wg21.link/over">over</A>]), user-defined conversions
(11.4.8.3 [<A href="https://wg21.link/class.conv.fct">class.conv.fct</A>]), allocation function for
placement new (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]), as well as
non-default initialization (9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]). A
constructor selected to copy or move an object of class type
is odr-used even if the call is actually elided by the
implementation (11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]). &#8212;<I>end
note</I>] An allocation or deallocation function for a class
is odr-used by a new expression appearing in a
potentially-evaluated expression as specified in
7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>] and 11.4.11 [<A href="https://wg21.link/class.free">class.free</A>]. A
deallocation function for a class is odr-used by a delete
expression appearing in a potentially-evaluated expression
as specified in 7.6.2.9 [<A href="https://wg21.link/expr.delete">expr.delete</A>] and
11.4.11 [<A href="https://wg21.link/class.free">class.free</A>].

</BLOCKQUOTE>

<P>There are a couple of problems with this specification.  First,
contrary to the note, the names of overloaded operators, conversion
functions, etc., do not appear in potentially-evaluated expressions,
so the normative text does not make the note true.  Also, the
&#8220;as specified in&#8221; references do not cover odr-use
explicitly, only the invocation of the functions.</P>

<P>One possible way of addressing these deficiencies would be a
blanket rule like,</P>

<BLOCKQUOTE>

A function is odr-used if it is invoked by a potentially-evaluated
expression.

</BLOCKQUOTE>

<P>(The existing wording about appearing in a potentially-evaluated
expression would still be needed for non-call references.)</P>

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

<OL>
<LI><P>Change 6.3 [<A href="https://wg21.link/basic.def.odr#2">basic.def.odr</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

An expression <INS>or conversion</INS>
is <I>potentially evaluated</I> unless it is
an unevaluated operand (7.2 [<A href="https://wg21.link/expr.prop">expr.prop</A>])<INS>,</INS>
<DEL>or</DEL> a subexpression thereof<INS>, or a conversion in
an initialization or conversion sequence in such a
context</INS>.  The set of <I>potential results</I> of an
expression <TT>e</TT> is defined as follows:...

</BLOCKQUOTE>

<LI><P>Cbange 6.3 [<A href="https://wg21.link/basic.def.odr#3">basic.def.odr</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

<P>A function is <I>named by <DEL>an
expression</DEL></I> <INS>an expression or conversion</INS>
as follows:</P>

<UL>
<LI><P>A function <DEL>whose name appears in an
expression</DEL> is named by <DEL>that</DEL> <INS>an</INS>
expression <INS>or conversion</INS> if it is the unique
<DEL>lookup</DEL> result <INS>of a name lookup</INS> or the
selected member of a set of overloaded functions
(6.5 [<A href="https://wg21.link/basic.lookup">basic.lookup</A>], 12.2 [<A href="https://wg21.link/over.match">over.match</A>],
12.3 [<A href="https://wg21.link/over.over">over.over</A>]) <INS>in an overload resolution
performed as part of forming that expression or
conversion</INS>, unless it is a pure virtual function and
either <DEL>its name is not</DEL>
<INS>the expression is not an <I>id-expression</I> naming
the function with an</INS>explicitly
qualified <INS>name</INS> or the expression forms a pointer
to member (7.6.2.2 [<A href="https://wg21.link/expr.unary.op">expr.unary.op</A>]). [<I>Note:</I> This
covers taking the address of functions
(7.3.4 [<A href="https://wg21.link/conv.func">conv.func</A>], 7.6.2.2 [<A href="https://wg21.link/expr.unary.op">expr.unary.op</A>]),
calls to named functions (7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>]),
operator overloading (Clause 12 [<A href="https://wg21.link/over">over</A>]),
user-defined conversions (11.4.8.3 [<A href="https://wg21.link/class.conv.fct">class.conv.fct</A>]),
allocation functions for <DEL>placement</DEL>
<I>new-expression</I>s (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]), as
well as non-default initialization
(9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]). A constructor selected to copy
or move an object of class type is considered to be named by
an expression <INS>or conversion</INS> even if the call is
actually elided by the implementation
(11.9.6 [<A href="https://wg21.link/class.copy.elision">class.copy.elision</A>]). &#8212;<I>end
note</I>]</P></LI>

<LI><P>A<DEL>n allocation or</DEL> deallocation function for
a class is named by a <I>new-expression</I> <INS>if it is
the single matching deallocation function for the allocation
function selected by o verload resolution,</INS> as
specified in 7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>] <DEL>and
11.4.11 [<A href="https://wg21.link/class.free">class.free</A>]</DEL>.</P></LI>

<LI><P>A deallocation function for a class is named by a <DEL>delete
expression</DEL>
<INS><I>delete-expression</I> if it is the selected usual
deallocation function</INS> as specified in
7.6.2.9 [<A href="https://wg21.link/expr.delete">expr.delete</A>] and
11.4.11 [<A href="https://wg21.link/class.free">class.free</A>].</P></LI>

</UL>

</BLOCKQUOTE>

<LI><P>Change 6.3 [<A href="https://wg21.link/basic.def.odr#7">basic.def.odr</A>] paragraph 7 as follows:</P></LI>

<BLOCKQUOTE>

A virtual member function is odr-used if it is not pure. A
function is odr-used if it is named by a
potentially-evaluated expression <INS>or conversion</INS>. A
non-placement...

</BLOCKQUOTE>

</OL>

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