<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1778</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="1778"></A><H4>1778.
  
<I>exception-specification</I> in explicitly-defaulted functions
</H4>
<B>Section: </B>9.6.2&#160; [<A href="https://wg21.link/dcl.fct.def.default">dcl.fct.def.default</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++14
 &#160;&#160;&#160;

 <B>Submitter: </B>USA
 &#160;&#160;&#160;

 <B>Date: </B>2013-09-25<BR><BR>


<A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3903.html#US23">N3690 comment
  US&#160;23<BR></A>

<P>[Moved to DR at the February, 2014 meeting.]</P>



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

<BLOCKQUOTE>

An explicitly-defaulted function may be declared <TT>constexpr</TT> only if
it would have been implicitly declared as <TT>constexpr</TT>, and may have an
explicit <I>exception-specification</I> only if it is compatible
(14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]) with the <I>exception-specification</I> on the
implicit declaration.

</BLOCKQUOTE>

<P>The requirement for <I>exception-specification</I>s has unfortunate
consequences for the standard library component <TT>atomic</TT>, as
described
in <A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2165">LWG
issue 2165</A>: the component cannot be used with a <TT>T</TT>
unless <TT>T</TT> is nothrow default constructible, even if
the <TT>std::atomic&lt;T&gt;</TT> variable is never default
initialized.</P>

<P><B>Proposed resolution (September, 2013):</B></P>

<P>Change 9.6.2 [<A href="https://wg21.link/dcl.fct.def.default">dcl.fct.def.default</A>] paragraphs 2 and 3 as follows:</P>

<BLOCKQUOTE>

<P>An explicitly-defaulted function may be declared <TT>constexpr</TT> only
if it would have been implicitly declared as <TT>constexpr</TT><DEL>, and
may have an explicit <I>exception-specification</I> only if it is
compatible (14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]) with
the <I>exception-specification</I> on the implicit declaration</DEL>. If a
function is explicitly defaulted on its first declaration,</P>

<UL>
<LI><P>it is implicitly considered to be <TT>constexpr</TT> if the
implicit declaration would be, and,</P></LI>

<LI><P>it is implicitly considered to have the
same <I>exception-specification</I> as if it had been implicitly declared
(14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]).</P></LI>

</UL>

<P><INS>If a function that is explicitly defaulted has an
explicit <I>exception-specification</I> that is not compatible
(14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]) with the <I>exception-specification</I> on the
implicit declaration, then</INS></P>

<UL>
<LI><P><INS>if the function is explicitly defaulted on its first
declaration, it is defined as deleted;</INS></P></LI>

<LI><P><INS>otherwise, the program is ill-formed.</INS></P></LI>

</UL>

<P>[<I>Example:</I>
</P>

<PRE>
  struct S {
    constexpr S() = default;            //<SPAN CLASS="cmnt"> ill-formed: implicit </SPAN>S()<SPAN CLASS="cmnt"> is not constexpr</SPAN>
    S(int a = 0) = default;             //<SPAN CLASS="cmnt"> ill-formed: default argument</SPAN>
    void operator=(const S&amp;) = default; //<SPAN CLASS="cmnt"> ill-formed: non-matching return type</SPAN>
    ~S() throw(int) = default;          //<SPAN CLASS="cmnt"> <DEL>ill-formed</DEL> <INS>deleted</INS>: exception specification does not match</SPAN>
  private:
    int i;
    S(S&amp;);                              //<SPAN CLASS="cmnt"> OK: private copy constructor</SPAN>
  };
  S::S(S&amp;) = default;                   //<SPAN CLASS="cmnt"> OK: defines copy constructor</SPAN>
</PRE>

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

</BLOCKQUOTE>

<P><B>Additional note, January, 2014:</B></P>

<P>
The proposed resolution appears to have the undesirable implication
that a special member function could become deleted after the
class is complete.  For example, given</P>

<PRE>
  struct S {
    S() noexcept(false) = default;
  };
</PRE>

<P>we need to check that the explicit exception specification
is compatible with the one on the implicit declaration.  After
the resolution of <A HREF="1330.html">issue 1330</A>, the
class is regarded as complete within <I>exception-specification</I>s,
per 11.4 [<A href="https://wg21.link/class.mem#2">class.mem</A>] paragraph 2.  This implies that the
explicit <I>exception-specification</I> can only be checked once
the class is complete.</P>

<P>The issue has been returned to "review" status to allow discussion
of this concern.</P>

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