[C++0x patch] clean up <future> slightly

Jonathan Wakely jwakely.gcc@gmail.com
Tue Dec 15 20:18:00 GMT 2009


	* include/std/future (unique_future::get, promise::set_value): Remove
	workaround for c++/34022.
	(packaged_task::get_future, packaged_task::operator()): Use
	__throw_bad_function_call.
	* testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust.
	* testsuite/30_threads/packaged_task/cons/copy_neg.cc: Likewise.
	* testsuite/30_threads/promise/cons/assign_neg.cc: Likewise.
	* testsuite/30_threads/promise/cons/copy_neg.cc: Likewise.

Tested x86_64/Linux and committed.

The <future> header needs a lot of changes to bring it up to date with
the WP, this patch doesn't do that, but I hope to get it done for 4.5
-------------- next part --------------
Index: include/std/future
===================================================================
--- include/std/future	(revision 155267)
+++ include/std/future	(working copy)
@@ -42,6 +42,7 @@
 #include <system_error>
 #include <exception>
 #include <cstdatomic>
+#include <bits/functexcept.h>
 
 namespace std
 {
@@ -172,7 +173,7 @@ namespace std
 	void
 	_M_set(_Res&& __res)
 	{
-	  ::new (_M_addr()) _Res(_Move_result<_Res>::_S_move(__res));
+	  ::new (_M_addr()) _Res(std::move(__res));
 	  _M_initialized = true;
 	}
 
@@ -183,27 +184,6 @@ namespace std
     };
 
 
-    /// Workaround for CWG issue 664 and c++/34022
-    template<typename _Res, bool = is_scalar<_Res>::value>
-      struct _Move_result;
-
-     /// Specialization for scalar types returns rvalue not rvalue-reference.
-    template<typename _Res>
-      struct _Move_result<_Res, true>
-      {
-	typedef _Res __rval_type;
-	static _Res _S_move(_Res __res) { return __res; }
-      };
-    
-    /// Specialization for non-scalar types returns rvalue-reference.
-    template<typename _Res>
-      struct _Move_result<_Res, false>
-      {
-	typedef _Res&& __rval_type;
-	static _Res&& _S_move(_Res& __res) { return std::move(__res); }
-      };
-
-
     // TODO: use template alias when available
     /*
       template<typename _Res>
@@ -426,7 +406,6 @@ namespace std
 
       typedef __basic_future<_Res> _Base_type;
       typedef typename _Base_type::__state_type __state_type;
-      typedef __future_base::_Move_result<_Res> _Mover;
 
       explicit
       unique_future(const __state_type& __state) : _Base_type(__state) { }
@@ -440,9 +419,9 @@ namespace std
       unique_future& operator=(const unique_future&) = delete;
 
       /// Retrieving the value
-      typename _Mover::__rval_type
+      _Res&&
       get()
-      { return _Mover::_S_move(this->_M_get_result()._M_value()); }
+      { return std::move(this->_M_get_result()._M_value()); }
     };
  
   /// Partial specialization for unique_future<R&>
@@ -586,7 +565,6 @@ namespace std
       template<typename> friend class packaged_task;
 
       typedef __future_base::_State 		_State;
-      typedef __future_base::_Move_result<_Res>	_Mover;
       typedef __future_base::_Result<_Res>	result_type;
       
       shared_ptr<_State>                        _M_future;
@@ -654,7 +632,7 @@ namespace std
       set_value(_Res&& __r)
       {
         if (!_M_satisfied())
-          _M_storage->_M_set(_Mover::_S_move(__r));
+          _M_storage->_M_set(std::move(__r));
         _M_future->_M_set_result(std::move(_M_storage));
       }
 
@@ -940,11 +918,9 @@ namespace std
         }
         __catch (const future_error& __e)
         {
-#ifdef __EXCEPTIONS
           if (__e.code() == future_errc::future_already_retrieved)
-	    throw std::bad_function_call();
-	  throw;
-#endif
+            __throw_bad_function_call();
+          __throw_exception_again;
         }
       }
 
@@ -953,13 +929,7 @@ namespace std
       operator()(_ArgTypes... __args)
       {
         if (!static_cast<bool>(_M_task) || _M_promise._M_satisfied())
-	  {
-#ifdef __EXCEPTIONS
-	    throw std::bad_function_call();
-#else
-	    __builtin_abort();
-#endif
-	  }
+          __throw_bad_function_call();
 
         __try
         {
Index: testsuite/30_threads/packaged_task/cons/assign_neg.cc
===================================================================
--- testsuite/30_threads/packaged_task/cons/assign_neg.cc	(revision 155267)
+++ testsuite/30_threads/packaged_task/cons/assign_neg.cc	(working copy)
@@ -33,4 +33,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 32 }
-// { dg-error "deleted function" "" { target *-*-* } 912 }
+// { dg-error "deleted function" "" { target *-*-* } 890 }
Index: testsuite/30_threads/packaged_task/cons/copy_neg.cc
===================================================================
--- testsuite/30_threads/packaged_task/cons/copy_neg.cc	(revision 155267)
+++ testsuite/30_threads/packaged_task/cons/copy_neg.cc	(working copy)
@@ -32,4 +32,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 31 }
-// { dg-error "deleted function" "" { target *-*-* } 911 }
+// { dg-error "deleted function" "" { target *-*-* } 889 }
Index: testsuite/30_threads/promise/cons/assign_neg.cc
===================================================================
--- testsuite/30_threads/promise/cons/assign_neg.cc	(revision 155267)
+++ testsuite/30_threads/promise/cons/assign_neg.cc	(working copy)
@@ -33,4 +33,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 32 }
-// { dg-error "deleted function" "" { target *-*-* } 630 }
+// { dg-error "deleted function" "" { target *-*-* } 608 }
Index: testsuite/30_threads/promise/cons/copy_neg.cc
===================================================================
--- testsuite/30_threads/promise/cons/copy_neg.cc	(revision 155267)
+++ testsuite/30_threads/promise/cons/copy_neg.cc	(working copy)
@@ -32,4 +32,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 31 }
-// { dg-error "deleted function" "" { target *-*-* } 614 }
+// { dg-error "deleted function" "" { target *-*-* } 592 }
Index: testsuite/30_threads/shared_future/cons/assign_neg.cc
===================================================================
--- testsuite/30_threads/shared_future/cons/assign_neg.cc	(revision 155267)
+++ testsuite/30_threads/shared_future/cons/assign_neg.cc	(working copy)
@@ -35,4 +35,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 34 }
-// { dg-error "deleted function" "" { target *-*-* } 514 }
+// { dg-error "deleted function" "" { target *-*-* } 493 }
Index: testsuite/30_threads/unique_future/cons/assign_neg.cc
===================================================================
--- testsuite/30_threads/unique_future/cons/assign_neg.cc	(revision 155267)
+++ testsuite/30_threads/unique_future/cons/assign_neg.cc	(working copy)
@@ -35,4 +35,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 34 }
-// { dg-error "deleted function" "" { target *-*-* } 440 }
+// { dg-error "deleted function" "" { target *-*-* } 419 }
Index: testsuite/30_threads/unique_future/cons/copy_neg.cc
===================================================================
--- testsuite/30_threads/unique_future/cons/copy_neg.cc	(revision 155267)
+++ testsuite/30_threads/unique_future/cons/copy_neg.cc	(working copy)
@@ -34,4 +34,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 33 }
-// { dg-error "deleted function" "" { target *-*-* } 439 }
+// { dg-error "deleted function" "" { target *-*-* } 418 }


More information about the Libstdc++ mailing list