summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/future
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-07-22 20:10:38 +0100
committerJonathan Wakely <jwakely@redhat.com>2020-07-22 20:11:00 +0100
commit1f53367fb5f16985e82c39f56368b956292cf86c (patch)
tree557ab60dd23a3f0fa24b28f4f1d6ac0277ef50ed /libstdc++-v3/include/std/future
parente55ba804d3b8de86a430a8a5553dfc1ad06daa74 (diff)
libstdc++: Add static assertions to futures and promises [LWG 3458]
LWG recently decided it should be ill-formed to instantiate std::future and std::shared_future for types that can't be returned from a function. This adds static assertions to enforce it (std::future already failed, but this makes the error more understandable). LWG 3466 extends that to std::promise. The actual constraint is that t.~T() is well-formed for the primary template, but rejecting arrays and functions as done for futures matches that condition. libstdc++-v3/ChangeLog: * include/std/future (future, shared_future, promise): Add static assertions to the primary template to reject array and function types. * testsuite/30_threads/future/requirements/lwg3458.cc: New test. * testsuite/30_threads/promise/requirements/lwg3466.cc: New test. * testsuite/30_threads/shared_future/requirements/lwg3458.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/std/future')
-rw-r--r--libstdc++-v3/include/std/future15
1 files changed, 15 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index 6eef6864f4d..bdf4a75d694 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -763,6 +763,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Res>
class future : public __basic_future<_Res>
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3458. Is shared_future intended to work with arrays or function types?
+ static_assert(!is_array<_Res>{}, "result type is not an array");
+ static_assert(!is_function<_Res>{}, "result type is not a function");
+
friend class promise<_Res>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
@@ -893,6 +898,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Res>
class shared_future : public __basic_future<_Res>
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3458. Is shared_future intended to work with arrays or function types?
+ static_assert(!is_array<_Res>{}, "result type is not an array");
+ static_assert(!is_function<_Res>{}, "result type is not a function");
+
typedef __basic_future<_Res> _Base_type;
public:
@@ -1045,6 +1055,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Res>
class promise
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3466: Specify the requirements for promise/future/[...] consistently
+ static_assert(!is_array<_Res>{}, "result type is not an array");
+ static_assert(!is_function<_Res>{}, "result type is not a function");
+
typedef __future_base::_State_base _State;
typedef __future_base::_Result<_Res> _Res_type;
typedef __future_base::_Ptr<_Res_type> _Ptr_type;