Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51926 - sandbox/committee/rvalue_ref
From: dgregor_at_[hidden]
Date: 2009-03-23 00:18:10


Author: dgregor
Date: 2009-03-23 00:18:09 EDT (Mon, 23 Mar 2009)
New Revision: 51926
URL: http://svn.boost.org/trac/boost/changeset/51926

Log:
Implicitly make destructors noexcept
Text files modified:
   sandbox/committee/rvalue_ref/rvalue-ref-exception-safety.html | 40 ++++++++++++++++++++++++++++++++++++++--
   1 files changed, 38 insertions(+), 2 deletions(-)

Modified: sandbox/committee/rvalue_ref/rvalue-ref-exception-safety.html
==============================================================================
--- sandbox/committee/rvalue_ref/rvalue-ref-exception-safety.html (original)
+++ sandbox/committee/rvalue_ref/rvalue-ref-exception-safety.html 2009-03-23 00:18:09 EDT (Mon, 23 Mar 2009)
@@ -53,6 +53,7 @@
       <li>Move Constructors are Non-Throwing</li>
       <li>Destructors are Non-throwing</li>
       <li>The noexcept Block</li>
+ <li>Deprecate Exception Specifications</li>
       <li>Library Changes
         <ul>
           <li>Nothrow Moving and Copying Concepts</li>
@@ -543,7 +544,32 @@
 
 <h3 id="noexcept-destruct">Destructors are Non-throwing</h3>
 
-<p>All destructors will implicitly be declared <code>noexcept</code>
+<p>Nearly every operation that involves construction of an object also involves destruction of that object. Therefore, the vast majority of uses of a non-throwing move constructor will also require a non-throwing destructor. Non-throwing destructors are not new; in fact, the C++ Standard Library requires that destructors not throw exceptions, and it is very rare that destructors ever throw. For these reasons, we propose that all destructors be implicitly be declared <code>noexcept</code> and are, therefore, banned from throwing exceptions.</p>
+
+<p>Unlike with move constructors, there are some use cases for destructors that throw exceptions. One such example is a return value that can't be ignored, e.g.,</pre>
+
+<pre>
+class ImportantReturn {
+ int value;
+ bool eaten;
+
+public:
+ ImportantReturn(int v) : value(v), eaten(false) { }
+
+ ~ImportantReturn() {
+ if (!eaten) throw important_return_value_ignored(value);
+ }
+
+ operator int() const {
+ eaten = true;
+ return value;
+ }
+};
+</pre>
+
+<p>For these destructors (which are a very slim minority) we require a syntax to disable the implicit <code>noexcept</code>. We propose to use the syntax <code>throw(...)</code> to mean "this function can throw any exception." This syntax is already a Microsoft extension, and fits in well with existing syntax.</p>
+
+<p>Note that implicitly making destructors <code>noexcept</code> will break existing code for classes like <code>ImportantReturn</code>. Users will need to add the <code>throw(...)</code> specification on these destructors to return them to their C++03 behavior. Given that few destructors need to throw exceptions---and that such classes cannot be used with the C++03 or C++0x standard libraries---we expect that the impact of this breaking change will be small.</p>
 
 <h3 id="noexcept-block">The <code>noexcept</code> Block</h3>
 
@@ -573,6 +599,8 @@
 
 <p>The <code>noexcept</code> block states that no exceptions will be thrown by the code within its compound statement. An exception that escapes from a <code>noexcept</code> block results in undefined behavior.</p>
 
+<h3 id="exception-spec">Deprecate Exception Specifications</h3>
+
 <h3 id="library">Library Changes</h3>
 <p>The introduction of <code>noexcept</code> and its use throughout the standard library will require significant changes in a few areas. The changes are summarized below.</p>
 
@@ -609,6 +637,14 @@
 }
 </pre>
 
+<p>Finally, we improve the existing <code>NothrowDestructible</code> concept to statically check the no-throw requirements:</p>
+
+<pre>
+auto concept NothrowDestructible&lt;typename T&gt; : HasDestructor&lt;T&gt; {
+ noexcept T::~T();
+}
+</pre>
+
 <h4 id="aggregate">Move Constructors and Move Assignment Operators</h4>
 
 <p>Throughout the library, each class template that aggregates other templates and has a move constructor will need to have its move constructor and move assignment operator be specified as <code>noexcept</code> and only be provided when the operations they use are known to be <code>noexcept</code>. We summarize the changes here, but have omitted the changes for some library components pending a full review of the library.<p>
@@ -675,5 +711,5 @@
 
 <hr>
 <address></address>
-<!-- hhmts start --> Last modified: Sun Mar 22 20:41:22 PDT 2009 <!-- hhmts end -->
+<!-- hhmts start --> Last modified: Sun Mar 22 21:19:01 PDT 2009 <!-- hhmts end -->
 </body> </html>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk