summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog139
-rw-r--r--libstdc++-v3/config/abi/pre/gnu.ver3
-rw-r--r--libstdc++-v3/include/Makefile.am1
-rw-r--r--libstdc++-v3/include/Makefile.in1
-rw-r--r--libstdc++-v3/include/bits/random.h87
-rw-r--r--libstdc++-v3/include/bits/random.tcc207
-rw-r--r--libstdc++-v3/include/std/future925
-rw-r--r--libstdc++-v3/src/Makefile.am6
-rw-r--r--libstdc++-v3/src/Makefile.in17
-rw-r--r--libstdc++-v3/src/future.cc73
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc5
-rw-r--r--libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc26
-rw-r--r--libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc49
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc53
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc64
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc36
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc35
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc49
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc49
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc47
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc55
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc57
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc49
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc56
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc60
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc48
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc51
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc65
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc53
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc49
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc34
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/cons/1.cc46
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc36
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc35
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/cons/move.cc55
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc56
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc52
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc57
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc49
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc95
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc105
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc88
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc87
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/swap.cc46
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc34
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc38
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc42
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc45
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc41
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc78
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc127
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc70
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc70
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc51
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc56
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc56
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc64
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc34
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc38
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc37
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc45
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc41
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc70
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc97
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc64
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc65
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc48
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc54
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc53
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc58
-rw-r--r--libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc34
-rw-r--r--libstdc++-v3/testsuite/performance/30_threads/future/polling.cc55
72 files changed, 4653 insertions, 168 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 29747b18c8e..cefde03746f 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,142 @@
+2009-06-21 Jonathan Wakely <jwakely.gcc@gmail.com>
+
+ * include/std/future: New.
+ * include/Makefile.am: Add.
+ * include/Makefile.in: Regenerate.
+ * src/future.cc: New.
+ * src/Makefile.am: Add.
+ * src/Makefile.in: Regenerate.
+ * config/abi/pre/gnu.ver: Add export.
+ * testsuite/30_threads/headers/future/std_c++0x_neg.cc: New.
+ * testsuite/30_threads/headers/future/types_std_c++0x.cc: New.
+ * testsuite/30_threads/packaged_task/cons/1.cc: New.
+ * testsuite/30_threads/packaged_task/cons/2.cc: New.
+ * testsuite/30_threads/packaged_task/cons/assign_neg.cc: New.
+ * testsuite/30_threads/packaged_task/cons/copy_neg.cc: New.
+ * testsuite/30_threads/packaged_task/cons/move_assign.cc: New.
+ * testsuite/30_threads/packaged_task/cons/move.cc: New.
+ * testsuite/30_threads/packaged_task/members/boolconv.cc: New.
+ * testsuite/30_threads/packaged_task/members/get_future.cc: New.
+ * testsuite/30_threads/packaged_task/members/get_future2.cc: New.
+ * testsuite/30_threads/packaged_task/members/invoke.cc: New.
+ * testsuite/30_threads/packaged_task/members/invoke2.cc: New.
+ * testsuite/30_threads/packaged_task/members/invoke3.cc: New.
+ * testsuite/30_threads/packaged_task/members/invoke4.cc: New.
+ * testsuite/30_threads/packaged_task/members/invoke5.cc: New.
+ * testsuite/30_threads/packaged_task/members/reset.cc: New.
+ * testsuite/30_threads/packaged_task/members/reset2.cc: New.
+ * testsuite/30_threads/packaged_task/members/swap.cc: New.
+ * testsuite/30_threads/packaged_task/requirements/
+ explicit_instantiation.cc: New.
+ * testsuite/30_threads/promise/cons/1.cc: New.
+ * testsuite/30_threads/promise/cons/assign_neg.cc: New.
+ * testsuite/30_threads/promise/cons/copy_neg.cc: New.
+ * testsuite/30_threads/promise/cons/move_assign.cc: New.
+ * testsuite/30_threads/promise/cons/move.cc: New.
+ * testsuite/30_threads/promise/members/get_future.cc: New.
+ * testsuite/30_threads/promise/members/get_future2.cc: New.
+ * testsuite/30_threads/promise/members/set_exception.cc: New.
+ * testsuite/30_threads/promise/members/set_exception2.cc: New.
+ * testsuite/30_threads/promise/members/set_value.cc: New.
+ * testsuite/30_threads/promise/members/set_value2.cc: New.
+ * testsuite/30_threads/promise/members/set_value3.cc: New.
+ * testsuite/30_threads/promise/members/swap.cc: New.
+ * testsuite/30_threads/promise/requirements/
+ explicit_instantiation.cc: New.
+ * testsuite/30_threads/shared_future/cons/assign_neg.cc: New.
+ * testsuite/30_threads/shared_future/cons/copy.cc: New.
+ * testsuite/30_threads/shared_future/cons/default_neg.cc: New.
+ * testsuite/30_threads/shared_future/cons/move.cc: New.
+ * testsuite/30_threads/shared_future/members/get.cc: New.
+ * testsuite/30_threads/shared_future/members/get2.cc: New.
+ * testsuite/30_threads/shared_future/members/has_exception.cc: New.
+ * testsuite/30_threads/shared_future/members/has_value.cc: New.
+ * testsuite/30_threads/shared_future/members/is_ready.cc: New.
+ * testsuite/30_threads/shared_future/members/wait.cc: New.
+ * testsuite/30_threads/shared_future/members/wait_for.cc: New.
+ * testsuite/30_threads/shared_future/members/wait_until.cc: New.
+ * testsuite/30_threads/shared_future/requirements/
+ explicit_instantiation.cc: New.
+ * testsuite/30_threads/unique_future/cons/assign_neg.cc: New.
+ * testsuite/30_threads/unique_future/cons/copy_neg.cc: New.
+ * testsuite/30_threads/unique_future/cons/default_neg.cc: New.
+ * testsuite/30_threads/unique_future/cons/move.cc: New.
+ * testsuite/30_threads/unique_future/members/get.cc: New.
+ * testsuite/30_threads/unique_future/members/get2.cc: New.
+ * testsuite/30_threads/unique_future/members/has_exception.cc: New.
+ * testsuite/30_threads/unique_future/members/has_value.cc: New.
+ * testsuite/30_threads/unique_future/members/is_ready.cc: New.
+ * testsuite/30_threads/unique_future/members/wait.cc: New.
+ * testsuite/30_threads/unique_future/members/wait_for.cc: New.
+ * testsuite/30_threads/unique_future/members/wait_until.cc: New.
+ * testsuite/30_threads/unique_future/requirements/
+ explicit_instantiation.cc: New.
+ * testsuite/performance/30_threads/future/polling.cc: New.
+
+2009-06-20 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * Revert last Change.
+
+2009-06-20 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR libstdc++/40497
+ * include/bits/stl_iterator_base_funcs.h (next, prev): Fix the
+ signature per the current C++1x draft (N2857).
+ * testsuite/24_iterators/operations/40497.cc: Add.
+
+2009-06-19 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/random.h (_Adaptor): Simplify for _DInputType always
+ a floating point type.
+ (uniform_int_distribution<>::uniform_int_distribution(_IntType,
+ _IntType)): Fix second default argument.
+ (uniform_int_distribution<>::_M_call): Remove.
+ (uniform_int_distribution<>::operator()(_UniformRandomNumberGenerator&,
+ const param_type&)): Only declare.
+ * include/bits/random.tcc (uniform_int_distribution<>::_M_call(
+ _UniformRandomNumberGenerator&, result_type, result_type, true_type):
+ Remove.
+ uniform_int_distribution<>::operator()(_UniformRandomNumberGenerator&,
+ const param_type&): Define here.
+ (geometric_distribution<>::operator()(_UniformRandomNumberGenerator&,
+ const param_type&), discrete_distribution<>::operator()
+ (_UniformRandomNumberGenerator&, const param_type&),
+ piecewise_constant_distribution<>::operator()
+ (_UniformRandomNumberGenerator&, const param_type&),
+ piecewise_linear_distribution<>::operator()
+ (_UniformRandomNumberGenerator&, const param_type&)): Use double as
+ the second template argument of _Adaptor.
+ * testsuite/26_numerics/random/uniform_int_distribution/cons/
+ default.cc: Adjust.
+
+2009-06-19 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/random.tcc (discrete_distribution<>::param_type::
+ param_type(size_t, double, double, _Func),
+ discrete_distribution<>::operator()(_UniformRandomNumberGenerator&,
+ const param_type&)): Tidy.
+ (piecewise_constant_distribution<>::param_type::_M_initialize):
+ Use reserve, fix.
+ (piecewise_constant_distribution<>::param_type::
+ param_type(initializer_list<>, _Func),
+ piecewise_constant_distribution<>::param_type::
+ param_type(size_t, _RealType, _RealType, _Func),
+ piecewise_linear_distribution<>::param_type::
+ param_type(initializer_list<>, _Func),
+ piecewise_linear_distribution<>::param_type::
+ param_type(size_t, _RealType, _RealType, _Func)): Use reserve, tidy.
+ (piecewise_constant_distribution<>::param_type::
+ param_type(_InputIteratorB, _InputIteratorB, _InputIteratorW),
+ piecewise_constant_distribution<>::
+ operator()(_UniformRandomNumberGenerator&, const param_type&),
+ piecewise_linear_distribution<>::
+ operator()(_UniformRandomNumberGenerator&, const param_type&)): Fix.
+ (operator>>(std::basic_istream<>&,
+ piecewise_constant_distribution<>&),
+ operator>>(std::basic_istream<>&, piecewise_linear_distribution<>&)):
+ Use reserve.
+ * include/bits/random.h: Minor cosmetic changes.
+
2009-06-17 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/23_containers/list/check_construct_destroy.h: New.
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 240e7bcf09b..3a24dc9fb16 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -964,6 +964,9 @@ GLIBCXX_3.4.12 {
_ZSt27__set_once_functor_lock_ptrPSt11unique_lockISt5mutexE;
_ZSt16__get_once_mutexv;
+ # future
+ _ZSt15future_category;
+
} GLIBCXX_3.4.11;
# Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 6a9c4f09ed4..b0fc483f20b 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -38,6 +38,7 @@ std_headers = \
${std_srcdir}/forward_list \
${std_srcdir}/fstream \
${std_srcdir}/functional \
+ ${std_srcdir}/future \
${std_srcdir}/iomanip \
${std_srcdir}/ios \
${std_srcdir}/iosfwd \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 0a0eeadc649..35fd0c26a33 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -295,6 +295,7 @@ std_headers = \
${std_srcdir}/forward_list \
${std_srcdir}/fstream \
${std_srcdir}/functional \
+ ${std_srcdir}/future \
${std_srcdir}/iomanip \
${std_srcdir}/ios \
${std_srcdir}/iosfwd \
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index e8edbf05dd4..099c5fae1a9 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -95,40 +95,23 @@ namespace std
_DInputType
min() const
- {
- if (is_integral<_DInputType>::value)
- return _M_g.min();
- else
- return _DInputType(0);
- }
+ { return _DInputType(0); }
_DInputType
max() const
- {
- if (is_integral<_DInputType>::value)
- return _M_g.max();
- else
- return _DInputType(1);
- }
+ { return _DInputType(1); }
/*
* Converts a value generated by the adapted random number generator
* into a value in the input domain for the dependent random number
* distribution.
- *
- * Because the type traits are compile time constants only the
- * appropriate clause of the if statements will actually be emitted
- * by the compiler.
*/
_DInputType
operator()()
{
- if (is_integral<_DInputType>::value)
- return _M_g();
- else
- return generate_canonical<_DInputType,
- numeric_limits<_DInputType>::digits,
- _Engine>(_M_g);
+ return std::generate_canonical<_DInputType,
+ std::numeric_limits<_DInputType>::digits,
+ _Engine>(_M_g);
}
private:
@@ -380,7 +363,7 @@ namespace std
static_assert(__w >= __l,
"mersenne_twister_engine template arguments out of bounds");
static_assert(__w <=
- static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ static_cast<size_t>(std::numeric_limits<_UIntType>::digits),
"mersenne_twister_engine template arguments out of bounds");
static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
"mersenne_twister_engine template arguments out of bounds");
@@ -558,8 +541,9 @@ namespace std
{
__glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
static_assert(__s > 0U && __r > __s
- && __w > 0U
- && __w <= static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ && __w > 0U
+ && __w <= static_cast<size_t>
+ (std::numeric_limits<_UIntType>::digits),
"template arguments out of bounds"
" in subtract_with_carry_engine");
@@ -922,7 +906,8 @@ namespace std
{
static_assert(__w > 0U
&& __w <=
- static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ static_cast<size_t>
+ (std::numeric_limits<_UIntType>::digits),
"template arguments out of bounds "
"in independent_bits_engine");
@@ -1507,7 +1492,8 @@ namespace std
typedef uniform_int_distribution<_IntType> distribution_type;
explicit
- param_type(_IntType __a = 0, _IntType __b = 9)
+ param_type(_IntType __a = 0,
+ _IntType __b = std::numeric_limits<_IntType>::max())
: _M_a(__a), _M_b(__b)
{
_GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
@@ -1531,7 +1517,8 @@ namespace std
* @brief Constructs a uniform distribution object.
*/
explicit
- uniform_int_distribution(_IntType __a = 0, _IntType __b = 9)
+ uniform_int_distribution(_IntType __a = 0,
+ _IntType __b = std::numeric_limits<_IntType>::max())
: _M_param(__a, __b)
{ }
@@ -1602,29 +1589,7 @@ namespace std
template<typename _UniformRandomNumberGenerator>
result_type
operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- typedef typename _UniformRandomNumberGenerator::result_type
- _UResult_type;
- return _M_call(__urng, __p.a(), __p.b(),
- typename is_integral<_UResult_type>::type());
- }
-
- private:
- template<typename _UniformRandomNumberGenerator>
- result_type
- _M_call(_UniformRandomNumberGenerator& __urng,
- result_type __min, result_type __max, true_type);
-
- template<typename _UniformRandomNumberGenerator>
- result_type
- _M_call(_UniformRandomNumberGenerator& __urng,
- result_type __min, result_type __max, false_type)
- {
- return result_type((__urng() - __urng.min())
- / (__urng.max() - __urng.min())
- * (__max - __min + 1)) + __min;
- }
+ const param_type& __p);
param_type _M_param;
};
@@ -4108,8 +4073,8 @@ namespace std
: _M_param(__wbegin, __wend)
{ }
- discrete_distribution(initializer_list<double> __wil)
- : _M_param(__wil)
+ discrete_distribution(initializer_list<double> __wl)
+ : _M_param(__wl)
{ }
template<typename _Func>
@@ -4240,7 +4205,7 @@ namespace std
_InputIteratorW __wbegin);
template<typename _Func>
- param_type(initializer_list<_RealType> __bil, _Func __fw);
+ param_type(initializer_list<_RealType> __bi, _Func __fw);
template<typename _Func>
param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
@@ -4276,9 +4241,9 @@ namespace std
{ }
template<typename _Func>
- piecewise_constant_distribution(initializer_list<_RealType> __bil,
+ piecewise_constant_distribution(initializer_list<_RealType> __bl,
_Func __fw)
- : _M_param(__bil, __fw)
+ : _M_param(__bl, __fw)
{ }
template<typename _Func>
@@ -4408,7 +4373,9 @@ namespace std
typedef piecewise_linear_distribution<_RealType> distribution_type;
friend class piecewise_linear_distribution<_RealType>;
- param_type();
+ param_type()
+ : _M_int(), _M_den(), _M_cp(), _M_m()
+ { _M_initialize(); }
template<typename _InputIteratorB, typename _InputIteratorW>
param_type(_InputIteratorB __bfirst,
@@ -4416,7 +4383,7 @@ namespace std
_InputIteratorW __wbegin);
template<typename _Func>
- param_type(initializer_list<_RealType> __bil, _Func __fw);
+ param_type(initializer_list<_RealType> __bl, _Func __fw);
template<typename _Func>
param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
@@ -4453,9 +4420,9 @@ namespace std
{ }
template<typename _Func>
- piecewise_linear_distribution(initializer_list<_RealType> __bil,
+ piecewise_linear_distribution(initializer_list<_RealType> __bl,
_Func __fw)
- : _M_param(__bil, __fw)
+ : _M_param(__bl, __fw)
{ }
template<typename _Func>
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index eb2ce4a4500..87c46186b57 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -644,13 +644,13 @@ namespace std
template<typename _UniformRandomNumberGenerator>
typename uniform_int_distribution<_IntType>::result_type
uniform_int_distribution<_IntType>::
- _M_call(_UniformRandomNumberGenerator& __urng,
- result_type __min, result_type __max, true_type)
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
{
// XXX Must be fixed to work well for *arbitrary* __urng.max(),
- // __urng.min(), __max, __min. Currently works fine only in the
- // most common case __urng.max() - __urng.min() >= __max - __min,
- // with __urng.max() > __urng.min() >= 0.
+ // __urng.min(), __param.b(), __param.a(). Currently works fine only
+ // in the most common case __urng.max() - __urng.min() >=
+ // __param.b() - __param.a(), with __urng.max() > __urng.min() >= 0.
typedef typename __gnu_cxx::__add_unsigned<typename
_UniformRandomNumberGenerator::result_type>::__type __urntype;
typedef typename __gnu_cxx::__add_unsigned<result_type>::__type
@@ -664,14 +664,14 @@ namespace std
const __urntype __urnmin = __urng.min();
const __urntype __urnmax = __urng.max();
const __urntype __urnrange = __urnmax - __urnmin;
- const __uctype __urange = __max - __min;
+ const __uctype __urange = __param.b() - __param.a();
const __uctype __udenom = (__urnrange <= __urange
? 1 : __urnrange / (__urange + 1));
do
__ret = (__urntype(__urng()) - __urnmin) / __udenom;
- while (__ret > __max - __min);
+ while (__ret > __param.b() - __param.a());
- return __ret + __min;
+ return __ret + __param.a();
}
template<typename _IntType, typename _CharT, typename _Traits>
@@ -799,7 +799,7 @@ namespace std
// The largest _RealType convertible to _IntType.
const double __thr =
std::numeric_limits<_IntType>::max() + __naf;
- __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
double __cand;
@@ -1985,30 +1985,31 @@ namespace std
return;
}
- double __sum = std::accumulate(_M_prob.begin(), _M_prob.end(), 0.0);
- // Now normalize the densities.
+ const double __sum = std::accumulate(_M_prob.begin(),
+ _M_prob.end(), 0.0);
+ // Now normalize the probabilites.
std::transform(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
std::bind2nd(std::divides<double>(), __sum));
- // Accumulate partial sums.
+ // Accumulate partial sums.
+ _M_cp.reserve(_M_prob.size());
std::partial_sum(_M_prob.begin(), _M_prob.end(),
std::back_inserter(_M_cp));
- // Make sure the last cumulative probablility is one.
+ // Make sure the last cumulative probability is one.
_M_cp[_M_cp.size() - 1] = 1.0;
}
template<typename _IntType>
template<typename _Func>
discrete_distribution<_IntType>::param_type::
- param_type(size_t __nw, double __xmin, double __xmax,
- _Func __fw)
+ param_type(size_t __nw, double __xmin, double __xmax, _Func __fw)
: _M_prob(), _M_cp()
{
- for (size_t __i = 0; __i < __nw; ++__i)
- {
- const double __x = ((__nw - __i - 0.5) * __xmin
- + (__i + 0.5) * __xmax) / __nw;
- _M_prob.push_back(__fw(__x));
- }
+ const size_t __n = __nw == 0 ? 1 : __nw;
+ const double __delta = (__xmax - __xmin) / __n;
+
+ _M_prob.reserve(__n);
+ for (size_t __k = 0; __k < __nw; ++__k)
+ _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
_M_initialize();
}
@@ -2020,17 +2021,14 @@ namespace std
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
- __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
const double __p = __aurng();
auto __pos = std::lower_bound(__param._M_cp.begin(),
__param._M_cp.end(), __p);
- if (__pos == __param._M_cp.end())
- return 0;
- const size_t __i = __pos - __param._M_cp.begin();
- return __i;
+ return __pos - __param._M_cp.begin();
}
template<typename _IntType, typename _CharT, typename _Traits>
@@ -2075,6 +2073,7 @@ namespace std
__is >> __n;
std::vector<double> __prob_vec;
+ __prob_vec.reserve(__n);
for (; __n != 0; --__n)
{
double __prob;
@@ -2098,6 +2097,7 @@ namespace std
if (_M_int.size() < 2)
{
_M_int.clear();
+ _M_int.reserve(2);
_M_int.push_back(_RealType(0));
_M_int.push_back(_RealType(1));
@@ -2107,21 +2107,21 @@ namespace std
return;
}
- double __sum = 0.0;
- for (size_t __i = 0; __i < _M_den.size(); ++__i)
- {
- __sum += _M_den[__i] * (_M_int[__i + 1] - _M_int[__i]);
- _M_cp.push_back(__sum);
- }
+ const double __sum = std::accumulate(_M_den.begin(),
+ _M_den.end(), 0.0);
- // Now normalize the densities...
std::transform(_M_den.begin(), _M_den.end(), _M_den.begin(),
std::bind2nd(std::divides<double>(), __sum));
- // ... and partial sums.
- std::transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(),
- std::bind2nd(std::divides<double>(), __sum));
- // Make sure the last cumulative probablility is one.
+
+ _M_cp.reserve(_M_den.size());
+ std::partial_sum(_M_den.begin(), _M_den.end(),
+ std::back_inserter(_M_cp));
+
+ // Make sure the last cumulative probability is one.
_M_cp[_M_cp.size() - 1] = 1.0;
+
+ for (size_t __k = 0; __k < _M_den.size(); ++__k)
+ _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
}
template<typename _RealType>
@@ -2132,17 +2132,19 @@ namespace std
_InputIteratorW __wbegin)
: _M_int(), _M_den(), _M_cp()
{
- do
+ if (__bbegin != __bend)
{
- _M_int.push_back(*__bbegin);
- ++__bbegin;
- if (__bbegin != __bend)
+ for (;;)
{
+ _M_int.push_back(*__bbegin);
+ ++__bbegin;
+ if (__bbegin == __bend)
+ break;
+
_M_den.push_back(*__wbegin);
++__wbegin;
}
}
- while (__bbegin != __bend);
_M_initialize();
}
@@ -2150,17 +2152,16 @@ namespace std
template<typename _RealType>
template<typename _Func>
piecewise_constant_distribution<_RealType>::param_type::
- param_type(initializer_list<_RealType> __bil, _Func __fw)
+ param_type(initializer_list<_RealType> __bl, _Func __fw)
: _M_int(), _M_den(), _M_cp()
{
- for (auto __biter = __bil.begin(); __biter != __bil.end(); ++__biter)
+ _M_int.reserve(__bl.size());
+ for (auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
_M_int.push_back(*__biter);
- for (size_t __i = 0; __i < _M_int.size() - 1; ++__i)
- {
- _RealType __x = 0.5 * (_M_int[__i] + _M_int[__i + 1]);
- _M_den.push_back(__fw(__x));
- }
+ _M_den.reserve(_M_int.size() - 1);
+ for (size_t __k = 0; __k < _M_int.size() - 1; ++__k)
+ _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
_M_initialize();
}
@@ -2171,18 +2172,16 @@ namespace std
param_type(size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
: _M_int(), _M_den(), _M_cp()
{
- for (size_t __i = 0; __i <= __nw; ++__i)
- {
- const _RealType __x = ((__nw - __i) * __xmin
- + __i * __xmax) / __nw;
- _M_int.push_back(__x);
- }
- for (size_t __i = 0; __i < __nw; ++__i)
- {
- const _RealType __x = ((__nw - __i - 0.5) * __xmin
- + (__i + 0.5) * __xmax) / __nw;
- _M_den.push_back(__fw(__x));
- }
+ const size_t __n = __nw == 0 ? 1 : __nw;
+ const _RealType __delta = (__xmax - __xmin) / __n;
+
+ _M_int.reserve(__n + 1);
+ for (size_t __k = 0; __k <= __nw; ++__k)
+ _M_int.push_back(__xmin + __k * __delta);
+
+ _M_den.reserve(__n);
+ for (size_t __k = 0; __k < __nw; ++__k)
+ _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
_M_initialize();
}
@@ -2194,7 +2193,7 @@ namespace std
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
- __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
const double __p = __aurng();
@@ -2202,8 +2201,9 @@ namespace std
__param._M_cp.end(), __p);
const size_t __i = __pos - __param._M_cp.begin();
- return __param._M_int[__i]
- + (__p - __param._M_cp[__i]) / __param._M_den[__i];
+ const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
+
+ return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
}
template<typename _RealType, typename _CharT, typename _Traits>
@@ -2253,6 +2253,7 @@ namespace std
__is >> __n;
std::vector<_RealType> __int_vec;
+ __int_vec.reserve(__n + 1);
for (size_t __i = 0; __i <= __n; ++__i)
{
_RealType __int;
@@ -2261,6 +2262,7 @@ namespace std
}
std::vector<double> __den_vec;
+ __den_vec.reserve(__n);
for (size_t __i = 0; __i < __n; ++__i)
{
double __den;
@@ -2284,10 +2286,12 @@ namespace std
if (_M_int.size() < 2)
{
_M_int.clear();
+ _M_int.reserve(2);
_M_int.push_back(_RealType(0));
_M_int.push_back(_RealType(1));
_M_den.clear();
+ _M_den.reserve(2);
_M_den.push_back(1.0);
_M_den.push_back(1.0);
@@ -2295,17 +2299,19 @@ namespace std
}
double __sum = 0.0;
- for (size_t __i = 0; __i < _M_int.size() - 1; ++__i)
+ _M_cp.reserve(_M_int.size() - 1);
+ _M_m.reserve(_M_int.size() - 1);
+ for (size_t __k = 0; __k < _M_int.size() - 1; ++__k)
{
- const _RealType __delta = _M_int[__i + 1] - _M_int[__i];
- __sum += 0.5 * (_M_den[__i + 1] + _M_den[__i]) * __delta;
+ const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
+ __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
_M_cp.push_back(__sum);
- _M_m.push_back((_M_den[__i + 1] - _M_den[__i]) / __delta);
+ _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
}
// Now normalize the densities...
std::transform(_M_den.begin(), _M_den.end(), _M_den.begin(),
- std::bind2nd(std::divides<double>(),__sum));
+ std::bind2nd(std::divides<double>(), __sum));
// ... and partial sums...
std::transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(),
std::bind2nd(std::divides<double>(), __sum));
@@ -2314,13 +2320,7 @@ namespace std
std::bind2nd(std::divides<double>(), __sum));
// Make sure the last cumulative probablility is one.
_M_cp[_M_cp.size() - 1] = 1.0;
- }
-
- template<typename _RealType>
- piecewise_linear_distribution<_RealType>::param_type::
- param_type()
- : _M_int(), _M_den(), _M_cp(), _M_m()
- { _M_initialize(); }
+ }
template<typename _RealType>
template<typename _InputIteratorB, typename _InputIteratorW>
@@ -2342,10 +2342,12 @@ namespace std
template<typename _RealType>
template<typename _Func>
piecewise_linear_distribution<_RealType>::param_type::
- param_type(initializer_list<_RealType> __bil, _Func __fw)
+ param_type(initializer_list<_RealType> __bl, _Func __fw)
: _M_int(), _M_den(), _M_cp(), _M_m()
{
- for (auto __biter = __bil.begin(); __biter != __bil.end(); ++__biter)
+ _M_int.reserve(__bl.size());
+ _M_den.reserve(__bl.size());
+ for (auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
{
_M_int.push_back(*__biter);
_M_den.push_back(__fw(*__biter));
@@ -2357,16 +2359,18 @@ namespace std
template<typename _RealType>
template<typename _Func>
piecewise_linear_distribution<_RealType>::param_type::
- param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
- _Func __fw)
+ param_type(size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
: _M_int(), _M_den(), _M_cp(), _M_m()
{
- for (size_t __i = 0; __i <= __nw; ++__i)
+ const size_t __n = __nw == 0 ? 1 : __nw;
+ const _RealType __delta = (__xmax - __xmin) / __n;
+
+ _M_int.reserve(__n + 1);
+ _M_den.reserve(__n + 1);
+ for (size_t __k = 0; __k <= __nw; ++__k)
{
- const _RealType __x = ((__nw - __i) * __xmin
- + __i * __xmax) / __nw;
- _M_int.push_back(__x);
- _M_den.push_back(__fw(__x));
+ _M_int.push_back(__xmin + __k * __delta);
+ _M_den.push_back(__fw(_M_int[__k] + __delta));
}
_M_initialize();
@@ -2379,31 +2383,30 @@ namespace std
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
- result_type __x;
- __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
const double __p = __aurng();
auto __pos = std::lower_bound(__param._M_cp.begin(),
__param._M_cp.end(), __p);
const size_t __i = __pos - __param._M_cp.begin();
+
+ const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
+
const double __a = 0.5 * __param._M_m[__i];
const double __b = __param._M_den[__i];
- const double __c = __param._M_cp[__i];
- const double __q = -0.5 * (__b
-#if _GLIBCXX_USE_C99_MATH_TR1
- + std::copysign(std::sqrt(__b * __b
- - 4.0 * __a * __c), __b));
-#else
- + (__b < 0.0 ? -1.0 : 1.0)
- * std::sqrt(__b * __b - 4.0 * __a * __c));
-#endif
- const double __x0 = __param._M_int[__i];
- const double __x1 = __q / __a;
- const double __x2 = __c / __q;
- __x = std::max(__x0 + __x1, __x0 + __x2);
+ const double __cm = __p - __pref;
+
+ _RealType __x = __param._M_int[__i];
+ if (__a == 0)
+ __x += __cm / __b;
+ else
+ {
+ const double __d = __b * __b + 4.0 * __a * __cm;
+ __x += 0.5 * (std::sqrt(__d) - __b) / __a;
+ }
- return __x;
+ return __x;
}
template<typename _RealType, typename _CharT, typename _Traits>
@@ -2453,6 +2456,7 @@ namespace std
__is >> __n;
std::vector<_RealType> __int_vec;
+ __int_vec.reserve(__n + 1);
for (size_t __i = 0; __i <= __n; ++__i)
{
_RealType __int;
@@ -2461,6 +2465,7 @@ namespace std
}
std::vector<double> __den_vec;
+ __den_vec.reserve(__n + 1);
for (size_t __i = 0; __i <= __n; ++__i)
{
double __den;
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
new file mode 100644
index 00000000000..c485b9614a1
--- /dev/null
+++ b/libstdc++-v3/include/std/future
@@ -0,0 +1,925 @@
+// <future> -*- C++ -*-
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file future
+ * This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_FUTURE
+#define _GLIBCXX_FUTURE 1
+
+#pragma GCC system_header
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+# include <c++0x_warning.h>
+#else
+
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <condition_variable>
+#include <system_error>
+#include <exception>
+#include <cstdatomic>
+
+#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
+ && defined(_GLIBCXX_ATOMIC_BUILTINS_4)
+
+namespace std
+{
+ /**
+ * @defgroup futures Futures
+ * @ingroup concurrency
+ *
+ * Classes for futures support.
+ * @{
+ */
+
+ /// Error code for futures
+ enum class future_errc
+ { broken_promise, future_already_retrieved, promise_already_satisfied };
+
+ // TODO: requires concepts
+ // concept_map ErrorCodeEnum<future_errc> { }
+ template<>
+ struct is_error_code_enum<future_errc> : public true_type { };
+
+ /// Points to a statically-allocated object derived from error_category.
+ extern const error_category* const future_category;
+
+ // TODO: requires constexpr
+ inline error_code make_error_code(future_errc __errc)
+ { return error_code(static_cast<int>(__errc), *future_category); }
+
+ // TODO: requires constexpr
+ inline error_condition make_error_condition(future_errc __errc)
+ { return error_condition(static_cast<int>(__errc), *future_category); }
+
+ /// Exception type thrown by futures.
+ class future_error : public logic_error
+ {
+ public:
+ explicit future_error(future_errc __ec)
+ : logic_error("std::future_error"), _M_code(make_error_code(__ec))
+ { }
+
+ const error_code& code() const throw() { return _M_code; }
+
+ const char* what() const throw() { return _M_code.message().c_str(); }
+
+ private:
+ error_code _M_code;
+ };
+
+ // Holds the result of a future
+ struct _Future_result_base
+ {
+ _Future_result_base() = default;
+ _Future_result_base(const _Future_result_base&) = delete;
+ _Future_result_base& operator=(const _Future_result_base&) = delete;
+
+ exception_ptr _M_error;
+
+ // _M_destroy() allows derived classes to control deallocation,
+ // which will be needed when allocator support is added to promise.
+ // See http://gcc.gnu.org/ml/libstdc++/2009-06/msg00032.html
+ virtual void _M_destroy() = 0;
+ struct _Deleter
+ {
+ void operator()(_Future_result_base* __fr) const { __fr->_M_destroy(); }
+ };
+
+ protected:
+ ~_Future_result_base() = default;
+ };
+
+ // TODO: use template alias when available
+ /*
+ template<typename _Res>
+ using _Future_ptr = unique_ptr<_Res, _Future_result_base::_Deleter>;
+ */
+ template<typename _Res>
+ struct _Future_ptr
+ {
+ typedef unique_ptr<_Res, _Future_result_base::_Deleter> type;
+ };
+
+ // State shared between a promise and one or more associated futures.
+ class _Future_state
+ {
+ typedef _Future_ptr<_Future_result_base>::type _Future_ptr_type;
+
+ public:
+ _Future_state() : _M_result(), _M_retrieved(false) { }
+
+ _Future_state(const _Future_state&) = delete;
+ _Future_state& operator=(const _Future_state&) = delete;
+
+ bool
+ is_ready()
+ { return _M_get() != 0; }
+
+ bool
+ has_exception()
+ {
+ _Future_result_base* const __res = _M_get();
+ return __res && !(__res->_M_error == 0);
+ }
+
+ bool
+ has_value()
+ {
+ _Future_result_base* const __res = _M_get();
+ return __res && (__res->_M_error == 0);
+ }
+
+ _Future_result_base&
+ wait()
+ {
+ unique_lock<mutex> __lock(_M_mutex);
+ if (!_M_ready())
+ _M_cond.wait(__lock, std::bind(&_Future_state::_M_ready, this));
+ return *_M_result;
+ }
+
+ template<typename _Rep, typename _Period>
+ bool
+ wait_for(const chrono::duration<_Rep, _Period>& __rel)
+ {
+ unique_lock<mutex> __lock(_M_mutex);
+ return _M_ready() || _M_cond.wait_for(__lock, __rel,
+ std::bind(&_Future_state::_M_ready, this));
+ }
+
+ template<typename _Clock, typename _Duration>
+ bool
+ wait_until(const chrono::time_point<_Clock, _Duration>& __abs)
+ {
+ unique_lock<mutex> __lock(_M_mutex);
+ return _M_ready() || _M_cond.wait_until(__lock, __abs,
+ std::bind(&_Future_state::_M_ready, this));
+ }
+
+ void
+ _M_set_result(_Future_ptr_type __res)
+ {
+ {
+ lock_guard<mutex> __lock(_M_mutex);
+ if (_M_ready())
+ throw future_error(future_errc::promise_already_satisfied);
+ _M_result.swap(__res);
+ }
+ _M_cond.notify_all();
+ }
+
+ void
+ _M_break_promise(_Future_ptr_type __res)
+ {
+ if (static_cast<bool>(__res))
+ {
+ __res->_M_error
+ = std::copy_exception(future_error(future_errc::broken_promise));
+ {
+ lock_guard<mutex> __lock(_M_mutex);
+ _M_result.swap(__res);
+ }
+ _M_cond.notify_all();
+ }
+ }
+
+ // called when this object is passed to a unique_future
+ void
+ _M_set_retrieved_flag()
+ {
+ if (_M_retrieved.test_and_set())
+ throw future_error(future_errc::future_already_retrieved);
+ }
+
+ private:
+ _Future_result_base*
+ _M_get()
+ {
+ lock_guard<mutex> __lock(_M_mutex);
+ return _M_result.get();
+ }
+
+ bool _M_ready() const { return static_cast<bool>(_M_result); }
+
+ _Future_ptr_type _M_result;
+ mutex _M_mutex;
+ condition_variable _M_cond;
+ atomic_flag _M_retrieved;
+ };
+
+ // workaround for CWG issue 664 and c++/34022
+ template<typename _Result, bool = is_scalar<_Result>::value>
+ struct _Move_future_result
+ {
+ typedef _Result&& __rval_type;
+ static _Result&& _S_move(_Result& __res) { return std::move(__res); }
+ };
+
+ // specialization for scalar types returns rvalue not rvalue-reference
+ template<typename _Result>
+ struct _Move_future_result<_Result, true>
+ {
+ typedef _Result __rval_type;
+ static _Result _S_move(_Result __res) { return __res; }
+ };
+
+ template<typename _Result>
+ struct _Future_result : _Future_result_base
+ {
+ _Future_result() : _M_initialized() { }
+
+ ~_Future_result()
+ {
+ if (_M_initialized)
+ _M_value().~_Result();
+ }
+
+ // return lvalue, future will add const or rvalue-reference
+ _Result& _M_value()
+ { return *static_cast<_Result*>(_M_addr()); }
+
+ void
+ _M_set(const _Result& __res)
+ {
+ ::new (_M_addr()) _Result(__res);
+ _M_initialized = true;
+ }
+
+ void
+ _M_set(_Result&& __res)
+ {
+ typedef _Move_future_result<_Result> _Mover;
+ ::new (_M_addr()) _Result(_Mover::_S_move(__res));
+ _M_initialized = true;
+ }
+
+ private:
+ void _M_destroy() { delete this; }
+
+ void* _M_addr() { return static_cast<void*>(&_M_storage); }
+
+ typename aligned_storage<sizeof(_Result),
+ alignment_of<_Result>::value>::type _M_storage;
+ bool _M_initialized;
+ };
+
+ template<typename _Result>
+ struct _Future_result<_Result&> : _Future_result_base
+ {
+ _Future_result() : _M_value_ptr() { }
+
+ _Result* _M_value_ptr;
+
+ void _M_destroy() { delete this; }
+ };
+
+ template<>
+ struct _Future_result<void> : _Future_result_base
+ {
+ void _M_destroy() { delete this; }
+ };
+
+ /// unique_future
+ template<typename _Result>
+ class unique_future;
+
+ /// shared_future
+ template<typename _Result>
+ class shared_future;
+
+ // common implementation for unique_future and shared_future
+ template<typename _Result>
+ class _Future_impl
+ {
+ public:
+ // disable copying
+ _Future_impl(const _Future_impl&) = delete;
+ _Future_impl& operator=(const _Future_impl&) = delete;
+
+ // functions to check state and wait for ready
+ bool is_ready() const { return this->_M_state->is_ready(); }
+
+ bool has_exception() const { return this->_M_state->has_exception(); }
+
+ bool has_value() const { return this->_M_state->has_value(); }
+
+ void wait() const { this->_M_state->wait(); }
+
+ template<typename _Rep, typename _Period>
+ bool
+ wait_for(const chrono::duration<_Rep, _Period>& __rel) const
+ { return this->_M_state->wait_for(__rel); }
+
+ template<typename _Clock, typename _Duration>
+ bool
+ wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const
+ { return this->_M_state->wait_until(__abs); }
+
+ protected:
+ // wait for the state to be ready and rethrow any stored exception
+ _Future_result<_Result>&
+ _M_get_result()
+ {
+ _Future_result_base& __res = this->_M_state->wait();
+ if (!(__res._M_error == 0))
+ rethrow_exception(__res._M_error);
+ return static_cast<_Future_result<_Result>&>(__res);
+ }
+
+ typedef shared_ptr<_Future_state> _State_ptr;
+
+ // construction of a unique_future by promise::get_future()
+ explicit
+ _Future_impl(const _State_ptr& __state)
+ : _M_state(__state)
+ {
+ if (static_cast<bool>(this->_M_state))
+ this->_M_state->_M_set_retrieved_flag();
+ else
+ throw future_error(future_errc::future_already_retrieved);
+ }
+
+ // copy construction from a shared_future
+ explicit
+ _Future_impl(const shared_future<_Result>&);
+
+ // move construction from a unique_future
+ explicit
+ _Future_impl(unique_future<_Result>&&);
+
+ _State_ptr _M_state;
+ };
+
+ /// promise
+ template<typename _Result>
+ class promise;
+
+ // primary template for unique_future
+ template<typename _Result>
+ class unique_future : public _Future_impl<_Result>
+ {
+ typedef _Move_future_result<_Result> _Mover;
+
+ public:
+ /// Move constructor
+ unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { }
+
+ // disable copying
+ unique_future(const unique_future&) = delete;
+ unique_future& operator=(const unique_future&) = delete;
+
+ // retrieving the value
+ typename _Mover::__rval_type
+ get()
+ { return _Mover::_S_move(this->_M_get_result()._M_value()); }
+
+ private:
+ typedef _Future_impl<_Result> _Base_type;
+ typedef typename _Base_type::_State_ptr _State_ptr;
+
+ friend class promise<_Result>;
+
+ explicit
+ unique_future(const _State_ptr& __state) : _Base_type(__state) { }
+ };
+
+ // partial specialization for unique_future<R&>
+ template<typename _Result>
+ class unique_future<_Result&> : public _Future_impl<_Result&>
+ {
+ public:
+ /// Move constructor
+ unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { }
+
+ // disable copying
+ unique_future(const unique_future&) = delete;
+ unique_future& operator=(const unique_future&) = delete;
+
+ // retrieving the value
+ _Result& get() { return *this->_M_get_result()._M_value_ptr; }
+
+ private:
+ typedef _Future_impl<_Result&> _Base_type;
+ typedef typename _Base_type::_State_ptr _State_ptr;
+
+ friend class promise<_Result&>;
+
+ explicit
+ unique_future(const _State_ptr& __state) : _Base_type(__state) { }
+ };
+
+ // specialization for unique_future<void>
+ template<>
+ class unique_future<void> : public _Future_impl<void>
+ {
+ public:
+ /// Move constructor
+ unique_future(unique_future&& __uf) : _Base_type(std::move(__uf)) { }
+
+ // disable copying
+ unique_future(const unique_future&) = delete;
+ unique_future& operator=(const unique_future&) = delete;
+
+ // retrieving the value
+ void get() { this->_M_get_result(); }
+
+ private:
+ typedef _Future_impl<void> _Base_type;
+ typedef _Base_type::_State_ptr _State_ptr;
+
+ friend class promise<void>;
+
+ explicit
+ unique_future(const _State_ptr& __state) : _Base_type(__state) { }
+ };
+
+ // primary template for unique_future
+ template<typename _Result>
+ class shared_future : public _Future_impl<_Result>
+ {
+ public:
+ /// Copy constructor
+ shared_future(const shared_future& __sf) : _Base_type(__sf) { }
+
+ /// Construct from a unique_future rvalue
+ shared_future(unique_future<_Result>&& __uf)
+ : _Base_type(std::move(__uf))
+ { }
+
+ shared_future& operator=(const shared_future&) = delete;
+
+ // retrieving the value
+ const _Result&
+ get()
+ { return this->_M_get_result()._M_value(); }
+
+ private:
+ typedef _Future_impl<_Result> _Base_type;
+ };
+
+ // partial specialization for shared_future<R&>
+ template<typename _Result>
+ class shared_future<_Result&> : public _Future_impl<_Result&>
+ {
+ public:
+ /// Copy constructor
+ shared_future(const shared_future& __sf) : _Base_type(__sf) { }
+
+ /// Construct from a unique_future rvalue
+ shared_future(unique_future<_Result&>&& __uf)
+ : _Base_type(std::move(__uf))
+ { }
+
+ shared_future& operator=(const shared_future&) = delete;
+
+ // retrieving the value
+ _Result& get() { return *this->_M_get_result()._M_value_ptr; }
+
+ private:
+ typedef _Future_impl<_Result&> _Base_type;
+ };
+
+ // specialization for shared_future<void>
+ template<>
+ class shared_future<void> : public _Future_impl<void>
+ {
+ public:
+ /// Copy constructor
+ shared_future(const shared_future& __sf) : _Base_type(__sf) { }
+
+ /// Construct from a unique_future rvalue
+ shared_future(unique_future<void>&& __uf)
+ : _Base_type(std::move(__uf))
+ { }
+
+ shared_future& operator=(const shared_future&) = delete;
+
+ // retrieving the value
+ void get() { this->_M_get_result(); }
+
+ private:
+ typedef _Future_impl<void> _Base_type;
+ };
+
+ // now we can define the protected _Future_impl constructors
+
+ template<typename _Result>
+ _Future_impl<_Result>::_Future_impl(const shared_future<_Result>& __sf)
+ : _M_state(__sf._M_state)
+ { }
+
+ template<typename _Result>
+ _Future_impl<_Result>::_Future_impl(unique_future<_Result>&& __uf)
+ : _M_state(std::move(__uf._M_state))
+ { }
+
+ template<typename> class packaged_task; // undefined
+
+ // primary template for promise
+ template<typename _Result>
+ class promise
+ {
+ public:
+ promise()
+ : _M_future(std::make_shared<_Future_state>()),
+ _M_storage(new _Future_result<_Result>())
+ { }
+
+ promise(promise&& __rhs)
+ : _M_future(std::move(__rhs._M_future)),
+ _M_storage(std::move(__rhs._M_storage))
+ { }
+
+ // TODO: requires allocator concepts
+ /*
+ template<typename _Allocator>
+ promise(allocator_arg_t, const _Allocator& __a);
+
+ template<typename _Allocator>
+ promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
+ */
+
+ promise(const promise&) = delete;
+
+ ~promise()
+ {
+ if (static_cast<bool>(_M_future) && !_M_future.unique())
+ _M_future->_M_break_promise(std::move(_M_storage));
+ }
+
+ // assignment
+ promise&
+ operator=(promise&& __rhs)
+ {
+ promise(std::move(__rhs)).swap(*this);
+ return *this;
+ }
+
+ promise& operator=(const promise&) = delete;
+
+ void
+ swap(promise& __rhs)
+ {
+ _M_future.swap(__rhs._M_future);
+ _M_storage.swap(__rhs._M_storage);
+ }
+
+ // retrieving the result
+ unique_future<_Result>
+ get_future()
+ { return unique_future<_Result>(_M_future); }
+
+ // setting the result
+ void
+ set_value(const _Result& __r)
+ {
+ if (!_M_satisfied())
+ _M_storage->_M_set(__r);
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ void
+ set_value(_Result&& __r)
+ {
+ if (!_M_satisfied())
+ _M_storage->_M_set(_Mover::_S_move(__r));
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ void
+ set_exception(exception_ptr __p)
+ {
+ if (!_M_satisfied())
+ _M_storage->_M_error = __p;
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ private:
+ template<typename> friend class packaged_task;
+ typedef _Move_future_result<_Result> _Mover;
+ bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
+ shared_ptr<_Future_state> _M_future;
+ typename _Future_ptr<_Future_result<_Result>>::type _M_storage;
+ };
+
+ // partial specialization for promise<R&>
+ template<typename _Result>
+ class promise<_Result&>
+ {
+ public:
+ promise()
+ : _M_future(std::make_shared<_Future_state>()),
+ _M_storage(new _Future_result<_Result&>())
+ { }
+
+ promise(promise&& __rhs)
+ : _M_future(std::move(__rhs._M_future)),
+ _M_storage(std::move(__rhs._M_storage))
+ { }
+
+ // TODO: requires allocator concepts
+ /*
+ template<typename _Allocator>
+ promise(allocator_arg_t, const _Allocator& __a);
+
+ template<typename _Allocator>
+ promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
+ */
+
+ promise(const promise&) = delete;
+
+ ~promise()
+ {
+ if (static_cast<bool>(_M_future) && !_M_future.unique())
+ _M_future->_M_break_promise(std::move(_M_storage));
+ }
+
+ // assignment
+ promise&
+ operator=(promise&& __rhs)
+ {
+ promise(std::move(__rhs)).swap(*this);
+ return *this;
+ }
+
+ promise& operator=(const promise&) = delete;
+
+ void
+ swap(promise& __rhs)
+ {
+ _M_future.swap(__rhs._M_future);
+ _M_storage.swap(__rhs._M_storage);
+ }
+
+ // retrieving the result
+ unique_future<_Result&>
+ get_future()
+ { return unique_future<_Result&>(_M_future); }
+
+ // setting the result
+ void
+ set_value(_Result& __r)
+ {
+ if (!_M_satisfied())
+ _M_storage->_M_value_ptr = &__r;
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ void
+ set_exception(exception_ptr __p)
+ {
+ if (!_M_satisfied())
+ _M_storage->_M_error = __p;
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ private:
+ template<typename> friend class packaged_task;
+ bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
+ shared_ptr<_Future_state> _M_future;
+ typename _Future_ptr<_Future_result<_Result&>>::type _M_storage;
+ };
+
+ // specialization for promise<void>
+ template<>
+ class promise<void>
+ {
+ public:
+ promise()
+ : _M_future(std::make_shared<_Future_state>()),
+ _M_storage(new _Future_result<void>())
+ { }
+
+ promise(promise&& __rhs)
+ : _M_future(std::move(__rhs._M_future)),
+ _M_storage(std::move(__rhs._M_storage))
+ { }
+
+ // TODO: requires allocator concepts
+ /*
+ template<typename _Allocator>
+ promise(allocator_arg_t, const _Allocator& __a);
+
+ template<typename _Allocator>
+ promise(allocator_arg_t, const _Allocator&, promise&& __rhs);
+ */
+
+ promise(const promise&) = delete;
+
+ ~promise()
+ {
+ if (static_cast<bool>(_M_future) && !_M_future.unique())
+ _M_future->_M_break_promise(std::move(_M_storage));
+ }
+
+ // assignment
+ promise&
+ operator=(promise&& __rhs)
+ {
+ promise(std::move(__rhs)).swap(*this);
+ return *this;
+ }
+
+ promise& operator=(const promise&) = delete;
+
+ void
+ swap(promise& __rhs)
+ {
+ _M_future.swap(__rhs._M_future);
+ _M_storage.swap(__rhs._M_storage);
+ }
+
+ // retrieving the result
+ unique_future<void>
+ get_future()
+ { return unique_future<void>(_M_future); }
+
+ // setting the result
+ void
+ set_value()
+ {
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ void
+ set_exception(exception_ptr __p)
+ {
+ if (!_M_satisfied())
+ _M_storage->_M_error = __p;
+ _M_future->_M_set_result(std::move(_M_storage));
+ }
+
+ private:
+ template<typename> friend class packaged_task;
+ bool _M_satisfied() { return !static_cast<bool>(_M_storage); }
+ shared_ptr<_Future_state> _M_future;
+ _Future_ptr<_Future_result<void>>::type _M_storage;
+ };
+
+ // TODO: requires allocator concepts
+ /*
+ template<typename _Result, class Alloc>
+ concept_map UsesAllocator<promise<_Result>, Alloc>
+ {
+ typedef Alloc allocator_type;
+ }
+ */
+
+ template<typename _Result, typename... _ArgTypes>
+ struct _Run_task
+ {
+ static void
+ _S_run(promise<_Result>& __p, function<_Result(_ArgTypes...)>& __f,
+ _ArgTypes... __args)
+ {
+ __p.set_value(__f(std::forward<_ArgTypes>(__args)...));
+ }
+ };
+
+ // specialization used by packaged_task<void(...)>
+ template<typename... _ArgTypes>
+ struct _Run_task<void, _ArgTypes...>
+ {
+ static void
+ _S_run(promise<void>& __p, function<void(_ArgTypes...)>& __f,
+ _ArgTypes... __args)
+ {
+ __f(std::forward<_ArgTypes>(__args)...);
+ __p.set_value();
+ }
+ };
+
+ template<typename _Result, typename... _ArgTypes>
+ class packaged_task<_Result(_ArgTypes...)>
+ {
+ public:
+ typedef _Result result_type;
+
+ // construction and destruction
+ packaged_task() { }
+
+ template<typename _Fn>
+ explicit
+ packaged_task(const _Fn& __fn) : _M_task(__fn) { }
+
+ template<typename _Fn>
+ explicit
+ packaged_task(_Fn&& __fn) : _M_task(std::move(__fn)) { }
+
+ explicit
+ packaged_task(_Result(*__fn)(_ArgTypes...)) : _M_task(__fn) { }
+
+ // TODO: requires allocator concepts
+ /*
+ template<typename _Fn, typename _Allocator>
+ explicit
+ packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn __fn)
+ : _M_task(__tag, __a, __fn), _M_promise(__tag, __a)
+ { }
+
+ template<typename _Fn, typename _Allocator>
+ explicit
+ packaged_task(allocator_arg_t __tag, const _Allocator& __a, _Fn&& __fn)
+ : _M_task(__tag, __a, std::move(__fn)), _M_promise(__tag, __a)
+ { }
+ */
+
+ ~packaged_task() = default;
+
+ // no copy
+ packaged_task(packaged_task&) = delete;
+ packaged_task& operator=(packaged_task&) = delete;
+
+ // move support
+ packaged_task(packaged_task&& __other)
+ { this->swap(__other); }
+
+ packaged_task& operator=(packaged_task&& __other)
+ {
+ packaged_task(std::move(__other)).swap(*this);
+ return *this;
+ }
+
+ void
+ swap(packaged_task& __other)
+ {
+ _M_task.swap(__other._M_task);
+ _M_promise.swap(__other._M_promise);
+ }
+
+ explicit operator bool() const { return static_cast<bool>(_M_task); }
+
+ // result retrieval
+ unique_future<_Result>
+ get_future()
+ {
+ try
+ {
+ return _M_promise.get_future();
+ }
+ catch (const future_error& __e)
+ {
+ if (__e.code() == future_errc::future_already_retrieved)
+ throw std::bad_function_call();
+ throw;
+ }
+ }
+
+ // execution
+ void
+ operator()(_ArgTypes... __args)
+ {
+ if (!static_cast<bool>(_M_task) || _M_promise._M_satisfied())
+ throw std::bad_function_call();
+ try
+ {
+ _Run_task<_Result, _ArgTypes...>::_S_run(_M_promise, _M_task,
+ std::forward<_ArgTypes>(__args)...);
+ }
+ catch (...)
+ {
+ _M_promise.set_exception(current_exception());
+ }
+ }
+
+ void reset() { promise<_Result>().swap(_M_promise); }
+
+ private:
+ function<_Result(_ArgTypes...)> _M_task;
+ promise<_Result> _M_promise;
+ };
+
+ // @} group futures
+}
+
+#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
+ // && _GLIBCXX_ATOMIC_BUILTINS_4
+
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
+#endif // _GLIBCXX_FUTURE
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index d218ceaa9ca..4295d4dda66 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -189,6 +189,7 @@ sources = \
condition_variable.cc \
chrono.cc \
thread.cc \
+ future.cc \
${host_sources} \
${host_sources_extra}
@@ -297,6 +298,11 @@ thread.lo: thread.cc
thread.o: thread.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
+future.lo: future.cc
+ $(LTCXXCOMPILE) -std=gnu++0x -c $<
+future.o: future.cc
+ $(CXXCOMPILE) -std=gnu++0x -c $<
+
if GLIBCXX_LDBL_COMPAT
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index 2da69a5d030..e9d5824dc4b 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -87,10 +87,11 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.cc \
ostream-inst.cc sstream-inst.cc streambuf-inst.cc streambuf.cc \
string-inst.cc valarray-inst.cc wlocale-inst.cc \
wstring-inst.cc mutex.cc condition_variable.cc chrono.cc \
- thread.cc atomicity.cc codecvt_members.cc collate_members.cc \
- ctype_members.cc messages_members.cc monetary_members.cc \
- numeric_members.cc time_members.cc basic_file.cc c++locale.cc \
- compatibility-ldbl.cc parallel_list.cc parallel_settings.cc
+ thread.cc future.cc atomicity.cc codecvt_members.cc \
+ collate_members.cc ctype_members.cc messages_members.cc \
+ monetary_members.cc numeric_members.cc time_members.cc \
+ basic_file.cc c++locale.cc compatibility-ldbl.cc \
+ parallel_list.cc parallel_settings.cc
am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \
ctype_members.lo messages_members.lo monetary_members.lo \
numeric_members.lo time_members.lo
@@ -113,7 +114,7 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo mutex.lo condition_variable.lo chrono.lo \
- thread.lo $(am__objects_1) $(am__objects_4)
+ thread.lo future.lo $(am__objects_1) $(am__objects_4)
am_libstdc___la_OBJECTS = $(am__objects_5)
libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
@@ -432,6 +433,7 @@ sources = \
condition_variable.cc \
chrono.cc \
thread.cc \
+ future.cc \
${host_sources} \
${host_sources_extra}
@@ -899,6 +901,11 @@ thread.lo: thread.cc
thread.o: thread.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
+future.lo: future.cc
+ $(LTCXXCOMPILE) -std=gnu++0x -c $<
+future.o: future.cc
+ $(CXXCOMPILE) -std=gnu++0x -c $<
+
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
@GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc
diff --git a/libstdc++-v3/src/future.cc b/libstdc++-v3/src/future.cc
new file mode 100644
index 00000000000..ab9d5dbcc69
--- /dev/null
+++ b/libstdc++-v3/src/future.cc
@@ -0,0 +1,73 @@
+// future -*- C++ -*-
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+#include <future>
+
+#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
+ && defined(_GLIBCXX_ATOMIC_BUILTINS_4)
+namespace
+{
+ struct future_error_category : public std::error_category
+ {
+ virtual const char*
+ name() const
+ { return "future"; }
+
+ virtual std::string message(int __ec) const
+ {
+ std::string __msg;
+ switch (std::future_errc(__ec))
+ {
+ case std::future_errc::broken_promise:
+ __msg = "Broken promise";
+ break;
+ case std::future_errc::future_already_retrieved:
+ __msg = "Future already retrieved";
+ break;
+ case std::future_errc::promise_already_satisfied:
+ __msg = "Promise already satisfied";
+ break;
+ default:
+ __msg = "Unknown error";
+ break;
+ }
+ return __msg;
+ }
+ };
+
+ const future_error_category&
+ __future_category_instance()
+ {
+ static const future_error_category __fec;
+ return __fec;
+ }
+}
+
+namespace std
+{
+ const error_category* const future_category = &__future_category_instance();
+}
+
+#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
+ // && _GLIBCXX_ATOMIC_BUILTINS_4
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc
index c1bfc04b0e1..0e83565e0de 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc
@@ -23,6 +23,7 @@
// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
#include <random>
+#include <limits>
#include <testsuite_hooks.h>
void
@@ -32,9 +33,9 @@ test01()
std::uniform_int_distribution<int> u;
VERIFY( u.a() == 0 );
- VERIFY( u.b() == 9 );
+ VERIFY( u.b() == std::numeric_limits<int>::max() );
VERIFY( u.min() == 0 );
- VERIFY( u.max() == 9 );
+ VERIFY( u.max() == std::numeric_limits<int>::max() );
}
int main()
diff --git a/libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc b/libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc
new file mode 100644
index 00000000000..5f021b8e5ac
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/headers/future/std_c++0x_neg.cc
@@ -0,0 +1,26 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++98" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <future> // { dg-excess-errors "In file included from" }
+
+// { dg-error "upcoming ISO" "" { target *-*-* } 31 }
+
+
+
diff --git a/libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc b/libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc
new file mode 100644
index 00000000000..16a54b4147a
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/headers/future/types_std_c++0x.cc
@@ -0,0 +1,49 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <future>
+
+void test01()
+{
+ typedef std::future_errc errc_t;
+
+ using std::future_category;
+
+ typedef std::future_error error_t;
+
+ typedef std::unique_future<int> uniq_t;
+ typedef std::unique_future<int&> uniqr_t;
+ typedef std::unique_future<void> uniqv_t;
+
+ typedef std::shared_future<int> shar_t;
+ typedef std::shared_future<int&> sharr_t;
+ typedef std::shared_future<void> sharv_t;
+
+ typedef std::promise<int> promise_t;
+ typedef std::promise<int&> promiser_t;
+ typedef std::promise<void> promisev_t;
+
+ typedef std::packaged_task<int> ptask_t;
+ typedef std::packaged_task<int&> ptaskr_t;
+ typedef std::packaged_task<void> ptaskv_t;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc
new file mode 100644
index 00000000000..a2414333e22
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/1.cc
@@ -0,0 +1,53 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::packaged_task;
+ using namespace __gnu_test;
+
+ packaged_task<int ()> p1;
+ VERIFY( !static_cast<bool>(p1) );
+ packaged_task<int& ()> p2;
+ VERIFY( !static_cast<bool>(p2) );
+ packaged_task<void ()> p3;
+ VERIFY( !static_cast<bool>(p3) );
+ packaged_task<ClassType ()> p4;
+ VERIFY( !static_cast<bool>(p4) );
+ packaged_task<AbstractClass& (int)> p5;
+ VERIFY( !static_cast<bool>(p5) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc
new file mode 100644
index 00000000000..98f5de73c4d
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/2.cc
@@ -0,0 +1,64 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+
+int f1() { return 0; }
+int& f2() { static int i; return i; }
+void f3() { }
+ClassType f4() { return ClassType(); }
+
+struct Derived : AbstractClass {
+ void rotate(int) { }
+ Derived& operator()(int i) { rotate(i); return *this; }
+} f5;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::packaged_task;
+
+ packaged_task<int ()> p1(f1);
+ VERIFY( static_cast<bool>(p1) );
+ packaged_task<int& ()> p2(f2);
+ VERIFY( static_cast<bool>(p2) );
+ packaged_task<void ()> p3(f3);
+ VERIFY( static_cast<bool>(p3) );
+ packaged_task<ClassType ()> p4(f4);
+ VERIFY( static_cast<bool>(p4) );
+ packaged_task<AbstractClass& (int)> p5(f5);
+ VERIFY( static_cast<bool>(p5) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc
new file mode 100644
index 00000000000..5f02dea0156
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+void test01()
+{
+ // assign
+ std::packaged_task<int()> p1;
+ std::packaged_task<int()> p2;
+ p1 = p2;
+}
+
+// { dg-error "used here" "" { target *-*-* } 32 }
+// { dg-error "deleted function" "" { target *-*-* } 856 }
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc
new file mode 100644
index 00000000000..6a50d7802aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+void test01()
+{
+ // copy
+ std::packaged_task<int()> p1;
+ std::packaged_task<int()> p2(p1);
+}
+
+// { dg-error "used here" "" { target *-*-* } 31 }
+// { dg-error "deleted function" "" { target *-*-* } 855 }
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc
new file mode 100644
index 00000000000..5335db39949
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move.cc
@@ -0,0 +1,49 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int f1() { return 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ // move
+ packaged_task<int()> p1(f1);
+ packaged_task<int()> p2(std::move(p1));
+ VERIFY( !static_cast<bool>(p1) );
+ VERIFY( static_cast<bool>(p2) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc
new file mode 100644
index 00000000000..c23e5e3b72b
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/move_assign.cc
@@ -0,0 +1,49 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int gen() { return 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ // move assign
+ std::packaged_task<int()> p1;
+ std::packaged_task<int()> p2(gen);
+ p1 = std::move(p2);
+ VERIFY( static_cast<bool>(p1) );
+ VERIFY( !static_cast<bool>(p2) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc
new file mode 100644
index 00000000000..c332b85741d
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/boolconv.cc
@@ -0,0 +1,47 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int zero() { return 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<int()> p1;
+ VERIFY( !static_cast<bool>(p1) );
+
+ std::packaged_task<int()> p2(zero);
+ VERIFY( static_cast<bool>(p2) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc
new file mode 100644
index 00000000000..c1bc129e26f
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future.cc
@@ -0,0 +1,55 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int& inc(int& i) { return ++i; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<int&(int&)> p1(inc);
+ std::unique_future<int&> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ int i1 = 0;
+
+ p1(i1);
+
+ int& i2 = f1.get();
+
+ VERIFY( &i1 == &i2 );
+ VERIFY( i1 == 1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc
new file mode 100644
index 00000000000..a6c9c61e5c8
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/get_future2.cc
@@ -0,0 +1,57 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+int& inc(int& i) { return ++i; }
+
+void test01()
+{
+ bool test = false;
+
+ std::packaged_task<int&(int&)> p1(inc);
+ p1.get_future();
+
+ try
+ {
+ p1.get_future();
+ VERIFY( false );
+ }
+ catch (std::bad_function_call&)
+ {
+ test = true;
+ }
+
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc
new file mode 100644
index 00000000000..2797b0606bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke.cc
@@ -0,0 +1,49 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int zero() { return 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<int()> p1(zero);
+ std::unique_future<int> f1 = p1.get_future();
+
+ p1();
+
+ VERIFY( static_cast<bool>(p1) );
+ VERIFY( f1.has_value() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc
new file mode 100644
index 00000000000..fae15dcac65
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke2.cc
@@ -0,0 +1,56 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+bool odd(unsigned i) { return i%2; }
+
+void test01()
+{
+ bool test = false;
+
+ std::packaged_task<bool(unsigned)> p1(odd);
+
+ p1(5);
+
+ try
+ {
+ p1(4);
+ }
+ catch (std::bad_function_call&)
+ {
+ test = true;
+ }
+
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc
new file mode 100644
index 00000000000..91d43413d35
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke3.cc
@@ -0,0 +1,60 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int& inc(int& i) { ++i; return i; }
+
+void test01()
+{
+ bool test = false;
+
+ std::packaged_task<void(int&)> p1(inc);
+
+ int i1 = 0;
+ p1(i1);
+
+ VERIFY( i1 == 1 );
+
+ try
+ {
+ p1(i1);
+ }
+ catch (std::bad_function_call&)
+ {
+ test = true;
+ }
+
+ VERIFY( i1 == 1 );
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc
new file mode 100644
index 00000000000..eefb313b7a4
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke4.cc
@@ -0,0 +1,48 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void thrower() { throw 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<void()> p1(thrower);
+ std::unique_future<void> f1 = p1.get_future();
+
+ p1();
+
+ VERIFY( f1.has_exception() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc
new file mode 100644
index 00000000000..925dc108fe9
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/invoke5.cc
@@ -0,0 +1,51 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <thread>
+#include <testsuite_hooks.h>
+
+void noop() { }
+void waiter(std::shared_future<void> f) { f.wait(); }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<void()> p1(noop);
+ std::shared_future<void> f1(p1.get_future());
+ std::thread t1(waiter, f1);
+
+ p1();
+
+ t1.join();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc
new file mode 100644
index 00000000000..66b9f3da669
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset.cc
@@ -0,0 +1,65 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+int zero() { return 0; }
+
+void test01()
+{
+ bool test = false;
+ using namespace std;
+
+ packaged_task<int()> p1(zero);
+ unique_future<int> f1 = p1.get_future();
+
+ p1.reset();
+ VERIFY( static_cast<bool>(p1) );
+
+ unique_future<int> f2 = p1.get_future();
+ VERIFY( !f2.is_ready() );
+
+ VERIFY( f1.has_exception() );
+ try
+ {
+ f1.get();
+ }
+ catch (future_error& e)
+ {
+ VERIFY( e.code() == make_error_code(future_errc::broken_promise) );
+ test = true;
+ }
+
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc
new file mode 100644
index 00000000000..69ee9a99213
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/reset2.cc
@@ -0,0 +1,53 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int zero() { return 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<int()> p1(zero);
+ std::unique_future<int> f1 = p1.get_future();
+
+ p1();
+ p1.reset();
+
+ VERIFY( static_cast<bool>(p1) );
+ VERIFY( f1.has_value() );
+
+ std::unique_future<int> f2 = p1.get_future();
+ VERIFY( !f2.is_ready() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc
new file mode 100644
index 00000000000..ced2a00529a
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/members/swap.cc
@@ -0,0 +1,49 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int zero() { return 0; }
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::packaged_task<int()> p1(zero);
+ std::packaged_task<int()> p2;
+ VERIFY( static_cast<bool>(p1) );
+ VERIFY( !static_cast<bool>(p2) );
+ p1.swap(p2);
+ VERIFY( !static_cast<bool>(p1) );
+ VERIFY( static_cast<bool>(p2) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc
new file mode 100644
index 00000000000..4d55603c83e
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/requirements/explicit_instantiation.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+using std::packaged_task;
+template class packaged_task<int()>;
+template class packaged_task<int&()>;
+template class packaged_task<void()>;
+template class packaged_task<ClassType(int)>;
+template class packaged_task<AbstractClass&(int)>;
diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc
new file mode 100644
index 00000000000..79120b7cd2b
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc
@@ -0,0 +1,46 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ using std::promise;
+ using namespace __gnu_test;
+
+ promise<int> p1;
+ promise<int&> p2;
+ promise<void> p3;
+ promise<ClassType> p4;
+ promise<AbstractClass&> p5;
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc
new file mode 100644
index 00000000000..0c77173d0bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+void test01()
+{
+ // assign
+ std::promise<int> p1;
+ std::promise<int> p2;
+ p1 = p2;
+}
+
+// { dg-error "used here" "" { target *-*-* } 32 }
+// { dg-error "deleted function" "" { target *-*-* } 583 }
diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc
new file mode 100644
index 00000000000..867c4be3133
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+void test01()
+{
+ // copy
+ std::promise<int> p1;
+ std::promise<int> p2(p1);
+}
+
+// { dg-error "used here" "" { target *-*-* } 31 }
+// { dg-error "deleted function" "" { target *-*-* } 567 }
diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc
new file mode 100644
index 00000000000..8b1e1399801
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc
@@ -0,0 +1,55 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ // move assign
+ promise<int> p1;
+ p1.set_value(3);
+ promise<int> p2(std::move(p1));
+ VERIFY( p2.get_future().get() == 3 );
+ try
+ {
+ p1.get_future();
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved));
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc
new file mode 100644
index 00000000000..c5bda4d3560
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc
@@ -0,0 +1,56 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ // move assign
+ promise<int> p1;
+ p1.set_value(3);
+ promise<int> p2;
+ p2 = move(p1);
+ VERIFY( p2.get_future().get() == 3 );
+ try
+ {
+ p1.get_future();
+ VERIFY( false );
+ }
+ catch (future_error& e)
+ {
+ VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved));
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc
new file mode 100644
index 00000000000..7e969908a99
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc
@@ -0,0 +1,52 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::unique_future<int&> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ int i1 = 0;
+
+ p1.set_value(i1);
+
+ int& i2 = f1.get();
+
+ VERIFY( &i1 == &i2 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc
new file mode 100644
index 00000000000..cc44fc47919
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc
@@ -0,0 +1,57 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+ using namespace std;
+
+ promise<int&> p1;
+ p1.get_future();
+
+ try
+ {
+ p1.get_future();
+ VERIFY( false );
+ }
+ catch (future_error& e)
+ {
+ VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved));
+ test = true;
+ }
+
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc
new file mode 100644
index 00000000000..e5b8f60aa3a
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc
@@ -0,0 +1,49 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ p1.set_exception(std::copy_exception(0));
+
+ VERIFY( f1.has_exception() );
+ VERIFY( !f1.has_value() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc
new file mode 100644
index 00000000000..3bbe28d48da
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc
@@ -0,0 +1,95 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1 = p1.get_future();
+
+ p1.set_exception(std::copy_exception(0));
+
+ try
+ {
+ p1.set_exception(std::copy_exception(1));
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ try
+ {
+ f1.get();
+ test = false;
+ }
+ catch(int i)
+ {
+ VERIFY( i == 0 );
+ }
+
+ VERIFY( test );
+}
+
+void test02()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1 = p1.get_future();
+
+ p1.set_value(2);
+
+ try
+ {
+ p1.set_exception(std::copy_exception(0));
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ VERIFY( f1.has_value() );
+ VERIFY( !f1.has_exception() );
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc
new file mode 100644
index 00000000000..978ef1914b0
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc
@@ -0,0 +1,105 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ p1.set_value(0);
+
+ int&& i1 = f1.get();
+
+ VERIFY( i1 == 0 );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ using __gnu_test::rvalstruct;
+
+ std::promise<rvalstruct> p1;
+ std::unique_future<rvalstruct> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ p1.set_value(rvalstruct(1));
+
+ rvalstruct r1(f1.get());
+
+ VERIFY( r1.valid );
+ VERIFY( r1.val == 1 );
+}
+
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::unique_future<int&> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ int i1 = 0;
+ p1.set_value(i1);
+ int& i2 = f1.get();
+
+ VERIFY( &i1 == &i2 );
+}
+
+void test04()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<void> p1;
+ std::unique_future<void> f1 = p1.get_future();
+
+ VERIFY( !f1.is_ready() );
+
+ p1.set_value();
+ f1.get();
+
+ VERIFY( f1.is_ready() );
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc
new file mode 100644
index 00000000000..58e2fe813e4
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc
@@ -0,0 +1,88 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1 = p1.get_future();
+
+ p1.set_value(1);
+
+ try
+ {
+ p1.set_value(2);
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ VERIFY( f1.has_value() );
+ VERIFY( f1.get() == 1 );
+ VERIFY( test );
+}
+
+void test02()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1 = p1.get_future();
+
+ p1.set_value(3);
+
+ try
+ {
+ p1.set_exception(std::copy_exception(4));
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ VERIFY( f1.has_value() );
+ VERIFY( !f1.has_exception() );
+ VERIFY( f1.get() == 3 );
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc
new file mode 100644
index 00000000000..92581964e3c
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc
@@ -0,0 +1,87 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+
+// Test promise::set_value() for deadlock by checking if the state is ready
+// during construction and destruction of the associated state.
+
+struct tester
+{
+ tester(int);
+ tester(const tester&);
+ tester() = delete;
+ ~tester();
+ tester& operator=(const tester&);
+};
+
+std::promise<tester> pglobal;
+std::unique_future<tester> fglobal = pglobal.get_future();
+
+tester::tester(int)
+{
+ bool test __attribute__((unused)) = true;
+ VERIFY (!fglobal.is_ready());
+}
+
+tester::tester(const tester&)
+{
+ bool test __attribute__((unused)) = true;
+ // if this copy happens while a mutex is locked next line could deadlock:
+ VERIFY (!fglobal.is_ready());
+}
+
+tester& tester::operator=(const tester&)
+{
+ bool test __attribute__((unused)) = true;
+ // if this copy happens while a mutex is locked next line could deadlock:
+ VERIFY (!fglobal.is_ready());
+ return *this;
+}
+
+tester::~tester()
+{
+ bool test __attribute__((unused)) = true;
+ VERIFY (fglobal.is_ready());
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ pglobal.set_value( tester(1) );
+
+ VERIFY( fglobal.is_ready() );
+}
+
+int main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc
new file mode 100644
index 00000000000..8bfbdfd6c8f
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc
@@ -0,0 +1,46 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::promise<int> p2;
+ p1.set_value(1);
+ p1.swap(p2);
+ VERIFY( !p1.get_future().is_ready() );
+ VERIFY( p2.get_future().is_ready() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc
new file mode 100644
index 00000000000..903b3ab146e
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+using std::promise;
+template class promise<int>;
+template class promise<int&>;
+template class promise<void>;
+template class promise<ClassType>;
+template class promise<ClassType&>;
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc
new file mode 100644
index 00000000000..7e3c96ffc1e
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/assign_neg.cc
@@ -0,0 +1,38 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+extern std::shared_future<int>& get();
+
+void test01()
+{
+ // assign
+ std::shared_future<int>& p1 = get();
+ std::shared_future<int>& p2 = get();
+ p1 = p2;
+}
+
+// { dg-error "used here" "" { target *-*-* } 34 }
+// { dg-error "deleted function" "" { target *-*-* } 474 }
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc
new file mode 100644
index 00000000000..16954a1d4c1
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/copy.cc
@@ -0,0 +1,42 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+extern std::unique_future<int>& get();
+
+void test01()
+{
+ using std::shared_future;
+
+ shared_future<int> p1 = get();
+ shared_future<int> p2(p1);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc
new file mode 100644
index 00000000000..cc4aadfce6f
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/default_neg.cc
@@ -0,0 +1,45 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ using std::shared_future;
+ using namespace __gnu_test;
+
+ shared_future<int> p1; // { dg-error "22: error: no match" }
+ shared_future<int&> p2; // { dg-error "23: error: no match" }
+ shared_future<void> p3; // { dg-error "23: error: no match" }
+ shared_future<ClassType> p4; // { dg-error "28: error: no match" }
+ shared_future<AbstractClass&> p5; // { dg-error "33: error: no match" }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+// { dg-excess-errors "note" }
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc b/libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc
new file mode 100644
index 00000000000..3494a10463f
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/cons/move.cc
@@ -0,0 +1,41 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+void test01()
+{
+ // construct from rvalue unique_future
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(std::move(f1));
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc
new file mode 100644
index 00000000000..bf773c31d52
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc
@@ -0,0 +1,78 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int value = 99;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ p1.set_value(value);
+ VERIFY( f1.get() == value );
+ VERIFY( f2.get() == value );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::shared_future<int&> f1(p1.get_future());
+ std::shared_future<int&> f2(f1);
+
+ p1.set_value(value);
+ VERIFY( &f1.get() == &value );
+ VERIFY( &f2.get() == &value );
+}
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<void> p1;
+ std::shared_future<void> f1(p1.get_future());
+ std::shared_future<void> f2(f1);
+
+ p1.set_value();
+ f1.get();
+ f2.get();
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc
new file mode 100644
index 00000000000..80dd368a973
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/get2.cc
@@ -0,0 +1,127 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <exception>
+#include <testsuite_hooks.h>
+
+int value = 99;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ p1.set_exception(std::copy_exception(value));
+ try
+ {
+ (void) f1.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+ try
+ {
+ (void) f2.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::shared_future<int&> f1(p1.get_future());
+ std::shared_future<int&> f2(f1);
+
+ p1.set_exception(std::copy_exception(value));
+ try
+ {
+ (void) f1.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+ try
+ {
+ (void) f2.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+}
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<void> p1;
+ std::shared_future<void> f1(p1.get_future());
+ std::shared_future<void> f2(f1);
+
+ p1.set_exception(std::copy_exception(value));
+ try
+ {
+ f1.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+ try
+ {
+ f2.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc
new file mode 100644
index 00000000000..97d398025e5
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_exception.cc
@@ -0,0 +1,70 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ VERIFY( !f1.has_exception() );
+ VERIFY( !f2.has_exception() );
+
+ p1.set_exception(std::copy_exception(1));
+
+ VERIFY( f1.has_exception() );
+ VERIFY( f2.has_exception() );
+}
+
+void test02()
+{
+ std::promise<int> p1;
+ bool test __attribute__((unused)) = true;
+
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ VERIFY( !f1.has_exception() );
+ VERIFY( !f2.has_exception() );
+
+ p1.set_value(1);
+
+ VERIFY( !f1.has_exception() );
+ VERIFY( !f2.has_exception() );
+}
+
+int main()
+{
+ test01();
+ test02();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc
new file mode 100644
index 00000000000..8903c825f88
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/has_value.cc
@@ -0,0 +1,70 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ VERIFY( !f1.has_value() );
+ VERIFY( !f2.has_value() );
+
+ p1.set_value(1);
+
+ VERIFY( f1.has_value() );
+ VERIFY( f2.has_value() );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ VERIFY( !f1.has_value() );
+ VERIFY( !f2.has_value() );
+
+ p1.set_exception(std::copy_exception(1));
+
+ VERIFY( !f1.has_value() );
+ VERIFY( !f2.has_value() );
+}
+
+int main()
+{
+ test01();
+ test02();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc
new file mode 100644
index 00000000000..eb2252a664b
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/is_ready.cc
@@ -0,0 +1,51 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ VERIFY( !f1.is_ready() );
+ VERIFY( !f2.is_ready() );
+
+ p1.set_value(1);
+
+ VERIFY( f1.is_ready() );
+ VERIFY( f2.is_ready() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc
new file mode 100644
index 00000000000..a4e325b0d96
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait.cc
@@ -0,0 +1,56 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <thread>
+#include <mutex>
+#include <testsuite_hooks.h>
+
+void wait(std::shared_future<void> f)
+{
+ f.wait();
+}
+
+void test01()
+{
+ std::promise<void> p1;
+ std::shared_future<void> f1(p1.get_future());
+
+ std::thread t1(wait, f1);
+ std::thread t2(wait, f1);
+ std::thread t3(wait, f1);
+
+ p1.set_value();
+ t1.join();
+ t2.join();
+ t3.join();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc
new file mode 100644
index 00000000000..408b6460225
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_for.cc
@@ -0,0 +1,56 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <chrono>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ std::chrono::milliseconds delay(100);
+
+ VERIFY( !f1.wait_for(delay) );
+ VERIFY( !f2.wait_for(delay) );
+
+ p1.set_value(1);
+
+ auto before = std::chrono::system_clock::now();
+ VERIFY( f1.wait_for(delay) );
+ VERIFY( f2.wait_for(delay) );
+ VERIFY( std::chrono::system_clock::now() < (before + 2*delay) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc
new file mode 100644
index 00000000000..561fb20952d
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/members/wait_until.cc
@@ -0,0 +1,64 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <chrono>
+#include <testsuite_hooks.h>
+
+std::chrono::system_clock::time_point make_time(int i)
+{
+ return std::chrono::system_clock::now() + std::chrono::milliseconds(i);
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::shared_future<int> f1(p1.get_future());
+ std::shared_future<int> f2(f1);
+
+ auto when = make_time(10);
+ VERIFY( !f1.wait_until(make_time(10)) );
+ VERIFY( std::chrono::system_clock::now() >= when );
+
+ when = make_time(10);
+ VERIFY( !f2.wait_until(make_time(10)) );
+ VERIFY( std::chrono::system_clock::now() >= when );
+
+ p1.set_value(1);
+
+ when = make_time(100);
+ VERIFY( f1.wait_until(when) );
+ VERIFY( f2.wait_until(when) );
+ VERIFY( std::chrono::system_clock::now() < when );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc
new file mode 100644
index 00000000000..4c1b3b276bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_future/requirements/explicit_instantiation.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+using std::shared_future;
+template class shared_future<int>;
+template class shared_future<int&>;
+template class shared_future<void>;
+template class shared_future<ClassType>;
+template class shared_future<ClassType&>;
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc
new file mode 100644
index 00000000000..e9525e4da7a
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/assign_neg.cc
@@ -0,0 +1,38 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+extern std::unique_future<int>& get();
+
+void test01()
+{
+ // assign
+ std::unique_future<int>& p1 = get();
+ std::unique_future<int>& p2 = get();
+ p1 = p2;
+}
+
+// { dg-error "used here" "" { target *-*-* } 34 }
+// { dg-error "deleted function" "" { target *-*-* } 394 }
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc
new file mode 100644
index 00000000000..bf40e054af0
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/copy_neg.cc
@@ -0,0 +1,37 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+extern std::unique_future<int>& get();
+
+void test01()
+{
+ // copy
+ std::unique_future<int>& p1 = get();
+ std::unique_future<int> p2(p1);
+}
+
+// { dg-error "used here" "" { target *-*-* } 33 }
+// { dg-error "deleted function" "" { target *-*-* } 393 }
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc
new file mode 100644
index 00000000000..ba5066bfcab
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/default_neg.cc
@@ -0,0 +1,45 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ using std::unique_future;
+ using namespace __gnu_test;
+
+ unique_future<int> p1; // { dg-error "22: error: no match" }
+ unique_future<int&> p2; // { dg-error "23: error: no match" }
+ unique_future<void> p3; // { dg-error "23: error: no match" }
+ unique_future<ClassType> p4; // { dg-error "28: error: no match" }
+ unique_future<AbstractClass&> p5; // { dg-error "33: error: no match" }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+// { dg-excess-errors "note" }
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc b/libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc
new file mode 100644
index 00000000000..17eaa914e4e
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/cons/move.cc
@@ -0,0 +1,41 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+
+void test01()
+{
+ // move
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+ std::unique_future<int> f2(std::move(f1));
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc
new file mode 100644
index 00000000000..5c9a4548491
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/get.cc
@@ -0,0 +1,70 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+int value = 99;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ p1.set_value(value);
+ VERIFY( f1.get() == value );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::unique_future<int&> f1(p1.get_future());
+
+ p1.set_value(value);
+ VERIFY( &f1.get() == &value );
+}
+
+void test03()
+{
+ std::promise<void> p1;
+ std::unique_future<void> f1(p1.get_future());
+
+ p1.set_value();
+ f1.get();
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc
new file mode 100644
index 00000000000..e6317fed838
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/get2.cc
@@ -0,0 +1,97 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <exception>
+#include <testsuite_hooks.h>
+
+int value = 99;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ p1.set_exception(std::copy_exception(value));
+ try
+ {
+ (void) f1.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::unique_future<int&> f1(p1.get_future());
+
+ p1.set_exception(std::copy_exception(value));
+ try
+ {
+ (void) f1.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+}
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<void> p1;
+ std::unique_future<void> f1(p1.get_future());
+
+ p1.set_exception(std::copy_exception(value));
+ try
+ {
+ f1.get();
+ VERIFY( false );
+ }
+ catch (int& e)
+ {
+ VERIFY( e == value );
+ }
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc
new file mode 100644
index 00000000000..1d5baf88393
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_exception.cc
@@ -0,0 +1,64 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ VERIFY( !f1.has_exception() );
+
+ p1.set_exception(std::copy_exception(1));
+
+ VERIFY( f1.has_exception() );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ VERIFY( !f1.has_exception() );
+
+ p1.set_value(1);
+
+ VERIFY( !f1.has_exception() );
+}
+
+int main()
+{
+ test01();
+ test02();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc
new file mode 100644
index 00000000000..f1f96f21ddc
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/has_value.cc
@@ -0,0 +1,65 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ VERIFY( !f1.has_value() );
+
+ p1.set_value(1);
+
+ VERIFY( f1.has_value() );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ VERIFY( !f1.has_value() );
+
+ p1.set_exception(std::copy_exception(1));
+
+ VERIFY( !f1.has_value() );
+}
+
+int main()
+{
+ test01();
+ test02();
+
+ return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc
new file mode 100644
index 00000000000..6f2b6885595
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/is_ready.cc
@@ -0,0 +1,48 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ VERIFY( !f1.is_ready() );
+
+ p1.set_value(1);
+
+ VERIFY( f1.is_ready() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc
new file mode 100644
index 00000000000..b9c9402cf31
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait.cc
@@ -0,0 +1,54 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <chrono>
+#include <thread>
+#include <mutex>
+#include <testsuite_hooks.h>
+
+
+void wait(std::unique_future<void>& f)
+{
+ f.wait();
+}
+
+void test01()
+{
+ std::promise<void> p1;
+ std::unique_future<void> f1(p1.get_future());
+
+ std::thread t1(wait, std::ref(f1));
+
+ p1.set_value();
+ t1.join();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc
new file mode 100644
index 00000000000..065240097b1
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_for.cc
@@ -0,0 +1,53 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <chrono>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ std::chrono::milliseconds delay(100);
+
+ VERIFY( !f1.wait_for(delay) );
+
+ p1.set_value(1);
+
+ auto before = std::chrono::system_clock::now();
+ VERIFY( f1.wait_for(delay) );
+ VERIFY( std::chrono::system_clock::now() < (before + delay) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc
new file mode 100644
index 00000000000..55bdcbcc76c
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/members/wait_until.cc
@@ -0,0 +1,58 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <chrono>
+#include <testsuite_hooks.h>
+
+std::chrono::system_clock::time_point make_time(int i)
+{
+ return std::chrono::system_clock::now() + std::chrono::milliseconds(i);
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::unique_future<int> f1(p1.get_future());
+
+ auto when = make_time(10);
+ VERIFY( !f1.wait_until(when) );
+ VERIFY( std::chrono::system_clock::now() >= when );
+
+ p1.set_value(1);
+
+ when = make_time(100);
+ VERIFY( f1.wait_until(when) );
+ VERIFY( std::chrono::system_clock::now() < when );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc
new file mode 100644
index 00000000000..01e5c5924b2
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/unique_future/requirements/explicit_instantiation.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+using std::unique_future;
+template class unique_future<int>;
+template class unique_future<int&>;
+template class unique_future<void>;
+template class unique_future<ClassType>;
+template class unique_future<ClassType&>;
diff --git a/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc b/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc
new file mode 100644
index 00000000000..21405e18ad4
--- /dev/null
+++ b/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc
@@ -0,0 +1,55 @@
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <thread>
+#include <testsuite_performance.h>
+
+void poll(std::shared_future<void> f)
+{
+ while (!f.is_ready())
+ { }
+}
+
+int main()
+{
+ using namespace __gnu_test;
+ time_counter time;
+ resource_counter resource;
+
+ const int n = 20;
+ std::promise<void> p;
+ std::shared_future<void> f = p.get_future();
+ std::thread pollers[n];
+ for (int i=0; i < n; ++i)
+ pollers[i] = std::thread(poll, f);
+
+ start_counters(time, resource);
+
+ for (int i = 0; i < 1000000; ++i)
+ (void)f.is_ready();
+ p.set_value();
+
+ for (int i=0; i < n; ++i)
+ pollers[i].join();
+
+ stop_counters(time, resource);
+ report_performance(__FILE__, "", time, resource);
+
+ return 0;
+}