<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1369: rethrow_exception may introduce data races</title>
<meta property="og:title" content="Issue 1369: rethrow_exception may introduce data races">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1369.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#NAD">NAD</a> status.</em></p>
<h3 id="1369"><a href="lwg-closed.html#1369">1369</a>. <code>rethrow_exception</code> may introduce data races</h3>
<p><b>Section:</b> 17.9.7 <a href="https://wg21.link/propagation">[propagation]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> BSI <b>Opened:</b> 2010-08-25 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#propagation">issues</a> in [propagation].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses GB-74</b></p>
<p>
One idea for the <code>exception_ptr</code> type was that a reference-counted
implementation could simply 'reactivate' the same
exception object in the context of a call to
<code>rethrow_exception</code>. Such an implementation would allow
the same exception object to be active in multiple threads
(such as when multiple threads join on a <code>shared_future</code>)
and introduce potential data races in any exception
handler that catches exceptions by reference - notably
existing library code written before this capability was
added. <code>rethrow_exception</code> should <em>always</em> make a copy
of the target exception object.
</p>

<p><i>[Resolution suggested by NB comment]</i></p>


<p>
Add the following to 18.8.5, [propogation]
</p>
<blockquote><p><ins>
<i>Throws</i>: a copy of the exception object to which <code>p</code> refers.
</ins></p></blockquote>

<p><i>[2011-03-15: Anthony drafts wording]</i></p>


<p><i>[2011-03-23 Madrid meeting]</i></p>


<p>No consensus for a change</p>



<p><b>Rationale:</b></p><p>It would break too many existing implementations</p>

<p id="res-1369"><b>Proposed resolution:</b></p>

<ol>
<li><p>Alter 14.2 <a href="https://wg21.link/except.throw">[except.throw]</a> p. 5 as follows:</p>

<blockquote><p>
5 When the thrown object is a class object, the copy/move constructor and the destructor shall be accessible,
even if the copy/move operation is elided ( [class.copy]). <ins>The copy constructor shall be
accessible, and is odr-used (6.3 <a href="https://wg21.link/basic.def.odr">[basic.def.odr]</a>), even if the copy operation is elided, 
or a move constructor used to construct the exception object.</ins>
</p></blockquote>
</li>

<li><p>Alter 17.9.7 <a href="https://wg21.link/propagation">[propagation]</a> p. 7 as follows:</p>

<blockquote><pre>
exception_ptr current_exception() noexcept;
</pre><blockquote>
<p>
7 <i>Returns</i>: An <code>exception_ptr</code> object that refers to <del>the currently handled exception 
(14.4 <a href="https://wg21.link/except.handle">[except.handle]</a>) or</del> a copy of the currently handled exception, or a null <code>exception_ptr</code> 
object if no exception is being handled. The referenced object shall remain valid at least as long as there 
is an <code>exception_ptr</code> object that refers to it. If the function needs to allocate memory and the 
attempt fails, it returns an <code>exception_ptr</code> object that refers to an instance of <code>bad_alloc</code>. 
It is unspecified whether the return values of two successive calls to <code>current_exception</code> refer to 
the same exception object. [ <i>Note</i>: That is, it is unspecified whether <code>current_exception</code> 
creates a new copy each time it is called. &mdash; <i>end note</i> ] If the attempt to copy the current 
exception object throws an exception,<ins> or is otherwise not possible,</ins> the function returns an 
<code>exception_ptr</code> object that refers to the thrown exception <ins>if any</ins> or, <del>if this is not possible,</del> 
to an instance of <code>bad_exception</code>. [ <i>Note</i>: The copy constructor of the thrown exception 
may also fail, so the implementation is allowed to substitute a <code>bad_exception</code> object to avoid 
infinite recursion. &mdash; <i>end note</i> ]
</p>
</blockquote></blockquote>
</li>

<li><p>Alter 17.9.7 <a href="https://wg21.link/propagation">[propagation]</a> p. 9 and add a new paragraph after p. 9 as follows:</p>

<blockquote><pre>
[[noreturn]] void rethrow_exception(exception_ptr p);
</pre><blockquote>
<p>
8 <i>Requires</i>: <code>p</code> shall not be a null pointer.
<p/>
9 <i>Throws</i>: <ins>a copy of</ins> the exception object to which <code>p</code> refers<ins>, or any exception 
thrown by the attempt to copy the exception object to which <code>p</code> refers</ins>.
<p/>
<ins>? <i>Synchronization</i>: Calls to <code>rethrow_exception</code> on <code>exception_ptr</code> objects
that refer to the same exception object shall appear to occur in a single total order. The completion 
of each call shall synchronize with (6.10.2 <a href="https://wg21.link/intro.multithread">[intro.multithread]</a>) the next call in that total order.</ins>
</p>
</blockquote></blockquote>
</li>
</ol>






</body>
</html>
