<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2082</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="2082"></A><H4>2082.
  
Referring to parameters in unevaluated operands of default arguments
</H4>
<B>Section: </B>9.3.4.7&#160; [<A href="https://wg21.link/dcl.fct.default">dcl.fct.default</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Faisal Vali
 &#160;&#160;&#160;

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


<P>[Adopted at the February, 2016 meeting.]</P>



<P>According to 9.3.4.7 [<A href="https://wg21.link/dcl.fct.default#9">dcl.fct.default</A>] paragraph 9,</P>

<BLOCKQUOTE>

A default argument is evaluated each time the function is
called with no argument for the corresponding parameter. The
order of evaluation of function arguments is
unspecified. Consequently, parameters of a function shall
not be used in a default argument, even if they are not
evaluated.

</BLOCKQUOTE>

<P>This prohibits use of parameters in unevaluated operands, e.g.,</P>

<PRE>
  void foo(int a = decltype(a){});
</PRE>

<P>This wording predates the concept of &#8220;unevaluated
operands&#8221; (the phrase &#8220;not evaluated&#8221; refers
to calls to the function where an actual argument is supplied and
thus the default argument is not used, not to unevaluated
operands) and should not apply to such cases.</P>

<P><B>Proposed resolution (October, 2015):</B></P>

<OL>
<LI><P>Change 9.3.4.7 [<A href="https://wg21.link/dcl.fct.default#7">dcl.fct.default</A>] paragraph 7 as follows:</P></LI>

<BLOCKQUOTE>

<P>
<DEL>Local variables</DEL> <INS>A local variable</INS>
shall not <DEL>be used</DEL> <INS>appear as a
potentially-evaluated expression</INS> in a default
argument. [<I>Example:</I>
</P>

<PRE>
  void f() {
    int i;
    extern void g(int x = i);           //<SPAN CLASS="cmnt"><INS> </INS>error</SPAN>
<INS>    extern void h(int x = sizeof(i));   //<SPAN CLASS="cmnt"> OK</SPAN></INS>
    //<SPAN CLASS="cmnt"> ...</SPAN>
  }
</PRE>

<P>&#8212;<I>end example</I>]</P>

</BLOCKQUOTE>

<LI><P>Change 9.3.4.7 [<A href="https://wg21.link/dcl.fct.default#8">dcl.fct.default</A>] paragraph 8 as follows:</P></LI>

<BLOCKQUOTE>

<P>
<INS>[<I>Note:</I></INS> The
keyword <TT>this</TT> <DEL>shall</DEL> <INS>may</INS>
not <DEL>be used</DEL> <INS>appear</INS> in a default
argument of a member function<INS>; see
_N4567_.5.1.1 [<A href="https://wg21.link/expr.prim.general">expr.prim.general</A>]</INS>. [<I>Example:</I>
</P>

<PRE>
  class A {
    void f(A* p = this) { } //<SPAN CLASS="cmnt"> error</SPAN>
  };
</PRE>

<P>&#8212;<I>end example</I>] <INS>&#8212;<I>end note</I>]</INS>
</P>

</BLOCKQUOTE>

<LI><P>Change 9.3.4.7 [<A href="https://wg21.link/dcl.fct.default#9">dcl.fct.default</A>] paragraph 9 as follows:</P></LI>

<BLOCKQUOTE>

<P>A default argument is evaluated each time the function is
called with no argument for the corresponding
parameter. <DEL>The order of evaluation of function
arguments is unspecified. Consequently, parameters of a
function shall not be used in a default argument, even if
they are not evaluated.</DEL> <INS>A parameter shall not
appear as a potentially-evaluated expression in a default
argument.</INS> Parameters of a function declared before a
default argument are in scope and can hide namespace and
class member names. [<I>Example:</I>
</P>

<PRE>
  int a;
  int f(int a, int b = a);         //<SPAN CLASS="cmnt"> error: parameter </SPAN>a
                                   //<SPAN CLASS="cmnt"> used as default argument</SPAN>
  typedef int I;
  int g(float I, int b = I(2));    //<SPAN CLASS="cmnt"> error: parameter </SPAN>I<SPAN CLASS="cmnt"> found</SPAN>
  int h(int a, int b = sizeof(a)); //<SPAN CLASS="cmnt"> <DEL>error, parameter </DEL></SPAN><DEL>a</DEL><SPAN CLASS="cmnt"><DEL> used</DEL> <INS>OK, unevaluated operand</INS></SPAN>
  <DEL>                                   //<SPAN CLASS="cmnt"> in default argument</SPAN></DEL>
</PRE>

<P>&#8212;<I>end example</I>] <DEL>Similarly,
a</DEL> <INS>A</INS> non-static member shall not <DEL>be
used</DEL> <INS>appear</INS> in a default argument<DEL>,
even if it is not evaluated,</DEL> unless it appears as
the <I>id-expression</I> of a class member access expression
(7.6.1.5 [<A href="https://wg21.link/expr.ref">expr.ref</A>]) or unless it is used to form a
pointer to member
(7.6.2.2 [<A href="https://wg21.link/expr.unary.op">expr.unary.op</A>]). [<I>Example:</I>...</P>

</BLOCKQUOTE>

</OL>

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