<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2746</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="2746"></A><H4>2746.
  
Checking of default template arguments
</H4>
<B>Section: </B>13.8.1&#160; [<A href="https://wg21.link/temp.res.general">temp.res.general</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Shafik Yaghmour
 &#160;&#160;&#160;

 <B>Date: </B>2022-12-13<BR>


<P>[Accepted as a DR at the March, 2024 meeting.]</P>



<P>Consider:</P>

<PRE>
  static int x = 1;
  template&lt;auto y = x&gt; void f() {}
</PRE>

<P>Is the definition of <TT>f</TT> well-formed? Since <TT>x</TT> is
not a constant expression, any use of the default template argument is
ill-formed, but for example <TT>f&lt;5&gt;()</TT> does not actually
use it.</P>

<P>Are implementations allowed or required to reject this situation,
even if the template is never instantiated?  If the default template
argument is dependent, checking may need to be deferred to
instantiations in any case.</P>

<P><B>Proposed resolution (approved by CWG 2024-03-01):</B></P>

<P>Change in 13.8.1 [<A href="https://wg21.link/temp.res.general#6">temp.res.general</A>] paragraph 6 as follows:</P>

<BLOCKQUOTE>

<P>The validity of a template may be checked prior to any instantiation.
[<I>Note :</I> ... &#8212;<I>end note</I>]</P>

<P>The program is ill-formed, no diagnostic required, if:</P>

<UL>
<LI>no valid specialization, ignoring
<I>static_assert-declaration</I>s that fail, can be generated for a
template or a substatement of a constexpr if statement
(8.5.2 [<A href="https://wg21.link/stmt.if">stmt.if</A>]) within a template and the template is not
instantiated, or</LI>

<LI class="ins">
no valid specialization, ignoring
<I>static_assert-declaration</I>s that fail, can be generated for
a default <I>template-argument</I> and the
default <I>template-argument</I> is not used in any instantiation, or
</LI>

<LI>any <I>constraint-expression</I> in the program, introduced or
otherwise, has (in its normal form) an atomic constraint A where no
satisfaction check of A could be well-formed and no satisfaction check
of A is performed, or</LI>

<LI>every valid specialization of a variadic template requires an
empty template parameter pack, or</LI>

<LI>a hypothetical instantiation of a template immediately following
its definition would be ill-formed due to a construct that does not
depend on a template parameter, or</LI>

<LI>the interpretation of such a construct in the hypothetical
instantiation is different from the interpretation of the
corresponding construct in any actual instantiation of the
template.</LI>
</UL>

</BLOCKQUOTE>

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