﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>N3155 - More on noexcept for the language support library</title>

  <style type="text/css">
    p {text-align:justify}
    li {text-align:justify}
    ins {background-color:#A0FFA0}
    del {background-color:#FF6666}
    
    tr.TITLE_ROW {text-align: center; font-weight: bold}
    tr.DELETED {background: #FF6666; text-decoration: line-through}
    tr.INSERTED {background: #FFFF99}
  </style>

  </head>

  <body>
<address>Document number: N3155=10-0145<br/>
  Date: 2010-10-14<br/>
  Author: J. Daniel Garcia<br/>
  Project: Programming Language C++, Library Working Group<br />
  Reply To: <a href="mailto:josedaniel.garcia@uc3m.es">josedaniel.garcia@uc3m.es</a>
</address>
 
<hr/>

<h1>N3155 - More on noexcept for the language support library</h1>

<p>During the Rapperswil meeting the Library Working Group decided to revise the library in terms of no except.
This paper presents proposed wording for some of these changes. The paper addresses National Body comments 
CH 16 and GB 60.</p>

<p>
This paper poposes additional changes to those presented in N3148, N3149 and N3150. Changes in this paper are
<b>restricted to chapter 18</b> (language support library).
</p>

<p>
All changes in this paper are against N3126.
</p>
<h2>Discussion</h2>

<h3>Start and termination functions</h3>

<p>
Exit functions <tt>_Exit()</tt> and <tt>abort()</tt> terminate <em>without executing destructors for objects of automatic, 
thread, or static storage duration and without calling functions passed to <tt>atexit()</tt></em>. They are good candidates
for <tt>noexcept</tt> as they will not be calling any functions being able to throw, as it is proposed in this paper.
</p>

<p>
<tt>atexit()</tt> functions may succeed or not in the registration action. In any case, they notify the failure by 
means of the return value. Thus, it is safe to make them <tt>noexcept</tt>. This also applies to <tt>at_quick_exit()</tt>.
This paper proposes making all of them <tt>noexcept</tt>.
</p>

<p>
<tt>exit()</tt> function may throw, as it may destroy user defined objets and may call functions registered with i
<tt>atexit()</tt>. Thus the cannot be make <tt>noexcept</tt>.
</p>

<p>
<tt>quick_exit()</tt> is not able to throw. It only calls to functions registered by means of <tt>at_quick_exit()</tt>. 
However, if a registered function throws an exception <tt>terminate</tt> is called. After that, it calls <tt>_Exit()</tt> 
which is also <tt>noexcept</tt>. This paper proposes to make it <tt>noexcept</tt>.
</p>

<h3>Class type_info</h3>

<p>
Class <tt>type_info</tt> are required to effectively store a pointer to a name for the type and and encoded value. Equallity comparisons
are expected to be implemented in terms of the encoded value, which shouldn't throw. This is also applicable to ordering (<tt>before</tt>).
</p>

<p>
However, for member <tt>name()</tt> it may be necessary some (pontentially throwing) string management.
</p>

<p>
There is no reason that makes the destructor, potentially throwing.
</>

<h3>Abnormal termination</h3>

Function <tt>terminate()</tt> cannot throw as it is called when exception handling must be abandoned.

<h3>Exception pointer management</h3>

<tt>make_exception_ptr()</tt> cannot throw. This may be inferred from the effects clause and the as-if code,
where very exception is caught and no one is rethrown.

<h3>Nested exceptions</h3>

Member function <tt>nested_ptr()</tt> returns the stored exception pointer. This cannot throw.

<h3>Range access for initializer list</h3>

Functions <tt>begin()</tt> and <tt>end()</tt> are specified in terms of calling non-throwing <tt>begin()</tt> and 
<tt>end()</tt> member functions of <tt>initializer_list</tt>. Thus, they cannot throw.

<h1>Proposed Wording</h1>

<h2>18.5 Start and termination</h2>

After p. 2
<pre>[[noreturn]] void _Exit(int status)<ins> noexcept;</ins></pre>

After p. 3
<pre>[[noreturn]] void abort(void)<ins> noexcept;</ins></pre>

After p. 4
<pre>
extern "C" int atexit(void (*f)(void))<ins> noexcept;</ins>
extern "C++" int atexit(void (*f)(void))<ins> noexcept;</ins>    
</pre>

After p. 8
<pre>
extern "C" int at_quick_exit(void (*f)(void))<ins> noexcept</ins>;
extern "C++" int at_quick_exit(void (*f)(void))<ins> noexcept</ins>;</pre>

After p. 11
<pre>[[noreturn]] void quick_exit(int status)<ins>noexcept</ins></pre>

<h2>18.7.1 Class type_info</h2>

<pre>
namespace std {
  class type_info {
  public:
    virtual ~type_info()<ins> noexcept</ins>;
    bool operator==(const type_info&amp; rhs) const<ins> noexcept</ins>;
    bool operator!=(const type_info&amp; rhs) const<ins> noexcept</ins>; 
    bool before(const type_info&amp; rhs) const<ins> noexcept</ins>;
...
 };
}
</pre>

After p. 1
<pre>bool operator==(const type_info&amp; rhs) const<ins> noexcept</ins>;</pre>

After p. 3
<pre>bool operator!=(const type_info&amp; rhs) const<ins> noexcept</ins>;</pre>

After p. 4
<pre>bool before(const type_info&amp; rhs) const<ins> noexcept</ins>;</pre>

<h2>18.8 Exception handling</h2>

After p. 1
<pre>
namespace std {
...
  [[noreturn]] void terminate()<ins> noexcept</ins>;
...
  template&lt;class E&gt; exception_ptr make_exception_ptr(E e)<ins> noexcept</ins>;
...
}

</pre>

<h2>18.8.4.3 terminate</h2>

Before p. 1
<pre>[[noreturn]] void terminate()<ins> noexcept</ins>;</pre>

<h2>18.8.6 Exception Propagation</h2>

After p. 10
<pre>template&lt;class E&gt; exception_ptr make_exception_ptr(E e)<ins> noexcept</ins>;</pre>

<h2>18.8.7 nested_exception</h2>

Before p. 1
<pre>
namespace std {
  class nested_exception {
  public:
...
  exception_ptr nested_ptr() const<ins> noexcept</ins>;
...
  };
}
</pre>

After p. 4
<pre>exception_ptr nested_ptr() const<ins> noexcept</ins>;</pre>

<h2>18.9 Initializer lists</h2>

After p. 1
<pre>
namespace std {
...
  // 18.9.3 initializer list range access
  template&lt;class E&gt; const E* begin(initializer_list&lt;E&gt; il)<ins> noexcept</ins>;
  template&lt;class E&gt; const E* end(initializer_list&lt;E&gt; il)<ins> noexcept</ins>;
}
</pre>

<h2>18.9.3 Initializer list range access</h2>

Before p. 1
<pre>template&lt;class E&gt; const E* begin(initializer_list&lt;E&gt; il)<ins> noexcept</ins>;</pre>

After p. 1
<pre>template&lt;class E&gt; const E* end(initializer_list&lt;E&gt; il)<ins> noexcept</ins>;</pre>




</body>
</html>
