﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>N3150 - Removing non-empty dynamic exception specifications from the 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: N3150=10-0140<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>N3150 - Removing non-empty dynamic exception specifications from the library</h1>

    During the Rapperswil meeting the Library Working Group decided to remove dynamic excepion specifications from the library, as this is a 
    deprecated feature now.

    This is mostly done by N3114. However, N3114 handles only empty dynamic exception specifications. The only place in the standard library where
    non-empty dynamic expection specifications are used is in some versions of <tt>operator new</tt>, which may throw <tt>std::bad_alloc</tt>. This
    paper corrects this, making them <tt>noexcept(false)</tt>.
    
    This paper presents proposed wording for this change.

    The paper partially addresses National Body comments CH 16 and GB 60.

    <h2>Discussion</h2>

    There are two points in the library where a non-empty dynamic exception specification is used:
    <ul>
      <li><tt>void* operator new(std::size_t)</tt></li>
      <li><tt>void* operator new[](std::size_t)</tt></li>
    </ul>

    For both of them the dynamic exception specification may be removed, making those operators <tt>noexcept(false)</tt> (they may throw).

    One could argue that then some clarification could be needed fo the exception which is thrown.

    However, for the first one, this is already done by 18.6.1.1/3, stating that <tt>bad_alloc</tt> may be thrown:

    <p><em>Required behavior</em>: Return a non-null pointer to suitably aligned storage (3.7.4), or else throw a 
    <tt>bad_alloc</tt> exception. This requirement is binding on a replacement version of this function.</p>

    For the second one, this is implicit in 18.6.1.2/3:
    
    <p><em>Required behavior</em>: Same as for operator <tt>new(std::size_t)</tt>. This requirement is binding on a 
    replacement version of this function.</p>

    Note that this is a way of implicitly stating that <tt>operator new[](std::size_t)</tt> may throw a <tt>std::bad_alloc</tt>.

    <h2>Identified changes</h2>

    All changes in this paper are against N3126.

    This paper proposes the following changes:
    <ul>
      <li>Remove <tt>throw(std::bad_alloc)</tt> from <tt>operator new(std::size_t)</tt> and <tt>operator new[](std::size_t)</tt>.</li>
      <li>Clarify that <tt>std::bad_alloc</tt> does not need to be implicitly introduced.</li>
    </ul>

    <h2>Acknoledgments</h2>

    Daniel Kr&uuml;gler reviewed this paper and provided helful feedback.

<h1>Wording</h1>

<h2>3.7.4 Dynamic storage duration</h2>

After p. 2
<pre>
void* operator new(std::size_t)<del> throw(std::bad_alloc)</del>;
void* operator new[](std::size_t)<del> throw(std::bad_alloc)</del>;
...
</pre>
These implicit declarations introduce only the function names <tt>operator new</tt>, <tt>operator new[]</tt>, <tt>operator
delete</tt>, <tt>operator delete[]</tt>. [ Note: the implicit declarations do not introduce the names <tt>std</tt>, <del><tt>std::bad_-
alloc</tt>,</del> and <tt>std::size_t</tt>, or any other names that the library uses to declare these names. Thus, a <em>newexpression</em>,
<em>delete-expression</em> or function call that refers to one of these functions without including the
header <tt>&lt;new&gt;</tt> is well-formed. However, referring to <tt>std</tt>, <del><tt>std::bad_alloc</tt>,</del> and <tt>std::size_t</tt> is ill-formed
unless the name has been declared by including the appropriate header. —<em>end note</em> ] Allocation and/or
deallocation functions can also be declared and defined for any class (12.5).

<h2>18.6 Dynamic memory management</h2>

After p. 1
<pre>
...
void* operator new(std::size_t size)<del> throw(std::bad_alloc)</del>;
...
void* operator new[](std::size_t size)<del> throw(std::bad_alloc)</del>;
...
</pre>

<h2>18.6.1.1 Single-object forms</h2>

Before p. 1
<pre>void* operator new(std::size_t size)<del> throw(std::bad_alloc)</del>;</pre>

<h2>18.6.1.2 Array forms</h2>

Before p. 1
<pre>void* operator new[](std::size_t size)<del> throw(std::bad_alloc)</del>;</pre>

</body>
</html>
