<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1089: Unify "Throws: Nothing." specifications</title>
<meta property="og:title" content="Issue 1089: Unify &quot;Throws: Nothing.&quot; specifications">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1089.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#C++11">C++11</a> status.</em></p>
<h3 id="1089"><a href="lwg-defects.html#1089">1089</a>. Unify "Throws: Nothing." specifications</h3>
<p><b>Section:</b> 32 <a href="https://wg21.link/thread">[thread]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2009-03-22 <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#thread">issues</a> in [thread].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses JP 76 [CD1]</b></p>

<p>
A description for "Throws: Nothing." are not unified.
</p>

<p>
At the part without throw, "Throws: Nothing." should be described.
</p>

<p>
Add "Throws: Nothing." to the following.
</p>

<ul>
<li>
32.4.3.7 <a href="https://wg21.link/thread.thread.static">[thread.thread.static]</a> p1
</li>
<li>
32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</a> p4
</li>
<li>
32.6.5.4.2 <a href="https://wg21.link/thread.lock.unique.cons">[thread.lock.unique.cons]</a> p6
</li>
<li>
32.7.4 <a href="https://wg21.link/thread.condition.condvar">[thread.condition.condvar]</a> p7 and p8
</li>
<li>
32.7.5 <a href="https://wg21.link/thread.condition.condvarany">[thread.condition.condvarany]</a> p6, p7, p19, p21 and p25
</li>
</ul>

<p><i>[
Summit:
]</i></p>

<blockquote><p>
Pass on to editor.
</p></blockquote>

<p><i>[
Post Summit:  Editor declares this non-editorial.
]</i></p>


<p><i>[
2009-08-01 Howard provided wording:
]</i></p>


<blockquote>

<p>
The definition of "<i>Throws:</i> Nothing." that I added is probably going to
be controversial, but I beg you to consider it seriously.
</p>

<blockquote>
<p>
In C++ there are three "flow control" options for a function:
</p>

<ol>
<li>
It can return, either with a value, or with <code>void</code>.
</li>
<li>
It can call a function which never returns, such as <code>std::exit</code> or
<code>std::terminate</code>.
</li>
<li>
It can throw an exception.
</li>
</ol>
<p>
The above list can be abbreviated with:
</p>
<ol>
<li><b>R</b>eturns.</li>
<li><b>E</b>nds program.</li>
<li><b>T</b>hrows exception.</li>
</ol>

<p>
In general a function can have the behavior of any of these 3, or any combination
of any of these three, depending upon run time data.
</p>

<ol>
<li><b>R</b></li>
<li><b>E</b></li>
<li><b>T</b></li>
<li><b>RE</b></li>
<li><b>RT</b></li>
<li><b>ET</b></li>
<li><b>RET</b></li>
</ol>

<p>
A function with no throw spec, and no documentation, is in general a <b>RET</b>
function.  It may return, it may end the program, or it may throw.  When we
specify a function with an empty throw spec:
</p>

<blockquote><pre>
void f() throw();
</pre></blockquote>

<p>
We are saying that <code>f()</code> is an <b>RE</b> function:  It may return or end
the program, but it will not throw.
</p>

<p>
I posit that there are very few places in the library half of the standard
where we intend for functions to be able to end the program (call <code>terminate</code>).
And none of those places where we do say <code>terminate</code> could be called,
do we currently say "<i>Throws:</i> Nothing.".
</p>

<p>
I believe that if we define "<i>Throws:</i> Nothing." to mean <b>R</b>,
we will both clarify many, many places in the standard, <em>and</em> give us a
good rationale for choosing between "<i>Throws:</i> Nothing." (<b>R</b>)
and <code>throw()</code> (<b>RE</b>) in the future.  Indeed, this may give us motivation
to change several <code>throw()</code>s to "<i>Throws:</i> Nothing.".
</p>
</blockquote>

<p>
I did not add the following changes as JP 76 requested as I believe we want to
allow these functions to throw:
</p>

<blockquote>
<p>
Add a paragraph under 32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</a> p4:
</p>

<blockquote><pre>
explicit lock_guard(mutex_type&amp; m);
</pre>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<p>
Add a paragraph under 32.6.5.4.2 <a href="https://wg21.link/thread.lock.unique.cons">[thread.lock.unique.cons]</a> p6:
</p>

<blockquote><pre>
explicit unique_lock(mutex_type&amp; m);
</pre>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<p>
Add a paragraph under 32.7.5 <a href="https://wg21.link/thread.condition.condvarany">[thread.condition.condvarany]</a> p19, p21 and p25:
</p>

<blockquote><pre>
template &lt;class Lock, class Rep, class Period&gt; 
  bool wait_for(Lock&amp; lock, const chrono::duration&lt;Rep, Period&gt;&amp; rel_time);
</pre>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<blockquote><pre>
template &lt;class Lock, class Duration, class Predicate&gt; 
  bool wait_until(Lock&amp; lock, const chrono::time_point&lt;Clock, Duration&gt;&amp; rel_time, Predicate pred);
</pre>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<blockquote><pre>
template &lt;class Lock, class Rep, class Period, class Predicate&gt; 
  bool wait_for(Lock&amp; lock, const chrono::duration&lt;Rep, Period&gt;&amp; rel_time, Predicate pred);
</pre>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

</blockquote>

</blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Defer pending further developments with exception restriction annotations.
</p></blockquote>

<p><i>[
2010-02-11 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>


<p><i>[
2010-02-24 Pete moved to Open:
]</i></p>


<blockquote><p>
A "<i>Throws:</i> Nothing" specification is not the place to say that a function
is not allowed to call <code>exit()</code>. While I agree with the thrust of the
proposed resolution, "doesn't throw exceptions" is a subset of "always returns
normally". If it's important to say that most library functions don't call
<code>exit()</code>, say so.
</p></blockquote>

<p><i>[
2010 Pittsburgh:
]</i></p>


<blockquote><p>
Move to Ready except for the added paragraph to 16.3.2.4 <a href="https://wg21.link/structure.specifications">[structure.specifications]</a>.
</p></blockquote>



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


<p>
Add a paragraph under 32.4.3.7 <a href="https://wg21.link/thread.thread.static">[thread.thread.static]</a> p1:
</p>

<blockquote><pre>
unsigned hardware_concurrency();
</pre>

<p>
-1- <i>Returns:</i> ...
</p>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<p>
Add a paragraph under 32.7.4 <a href="https://wg21.link/thread.condition.condvar">[thread.condition.condvar]</a> p7 and p8:
</p>

<blockquote>
<p>
<i>[Informational, not to be incluced in the WP: The POSIX spec allows only:</i>
</p>
<dl>
<dt><i>[EINVAL]</i></dt>
<dd><i>The value <code>cond</code> does not refer to an initialized condition variable. &mdash; end informational]</i></dd>
</dl>

<pre>
void notify_one();
</pre>

<p>
-7- <i>Effects:</i> ...
</p>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<blockquote><pre>
void notify_all();
</pre>

<p>
-8- <i>Effects:</i> ...
</p>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>


<p>
Add a paragraph under 32.7.5 <a href="https://wg21.link/thread.condition.condvarany">[thread.condition.condvarany]</a> p6 and p7:
</p>

<blockquote>
<pre>
void notify_one();
</pre>

<p>
-6- <i>Effects:</i> ...
</p>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>

<blockquote><pre>
void notify_all();
</pre>

<p>
-7- <i>Effects:</i> ...
</p>

<p><ins>
<i>Throws:</i> Nothing.
</ins></p>
</blockquote>







</body>
</html>
