aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2015-05-29 14:44:52 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2015-05-29 14:44:52 +0100
commit75eb64433edb2a48c471c50e729612a326d1b1e9 (patch)
tree81b349f28374a2ce6771d504093908e7f43c803e
parent6759eddee476abdfb5e847a7de3765309f4f1e2d (diff)
downloadgcc-75eb64433edb2a48c471c50e729612a326d1b1e9.zip
gcc-75eb64433edb2a48c471c50e729612a326d1b1e9.tar.gz
gcc-75eb64433edb2a48c471c50e729612a326d1b1e9.tar.bz2
future (__async_result_of): New alias template.
* include/std/future (__async_result_of): New alias template. (async): Use __async_result_of to pass decayed types to result_of. * testsuite/30_threads/async/lwg2021.cc: New. * doc/xml/manual/intro.xml: Document LWG 2021 status. From-SVN: r223866
-rw-r--r--libstdc++-v3/ChangeLog5
-rw-r--r--libstdc++-v3/doc/xml/manual/intro.xml6
-rw-r--r--libstdc++-v3/include/std/future28
-rw-r--r--libstdc++-v3/testsuite/30_threads/async/lwg2021.cc42
4 files changed, 70 insertions, 11 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 94c7963..9b53161 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,10 @@
2015-05-29 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/future (__async_result_of): New alias template.
+ (async): Use __async_result_of to pass decayed types to result_of.
+ * testsuite/30_threads/async/lwg2021.cc: New.
+ * doc/xml/manual/intro.xml: Document LWG 2021 status.
+
PR libstdc++/66327
* include/bits/stl_algobase.h (__equal<true>::equal): Do not call
memcmp with null pointers.
diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml
index b521089..f0c66a2 100644
--- a/libstdc++-v3/doc/xml/manual/intro.xml
+++ b/libstdc++-v3/doc/xml/manual/intro.xml
@@ -814,6 +814,12 @@ requirements of the license of GCC.
<listitem><para>Return the end of the filled range.
</para></listitem></varlistentry>
+ <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2021">2021</link>:
+ <emphasis>Further incorrect uses of <code>result_of</code></emphasis>
+ </term>
+ <listitem><para>Correctly decay types in signature of <code>std::async</code>.
+ </para></listitem></varlistentry>
+
</variablelist>
</section>
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index c4baf90..216a921 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -168,12 +168,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
deferred
};
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 2021. Further incorrect usages of result_of
template<typename _Fn, typename... _Args>
- future<typename result_of<_Fn(_Args...)>::type>
+ using __async_result_of = typename result_of<
+ typename decay<_Fn>::type(typename decay<_Args>::type...)>::type;
+
+ template<typename _Fn, typename... _Args>
+ future<__async_result_of<_Fn, _Args...>>
async(launch __policy, _Fn&& __fn, _Args&&... __args);
template<typename _Fn, typename... _Args>
- future<typename result_of<_Fn(_Args...)>::type>
+ future<__async_result_of<_Fn, _Args...>>
async(_Fn&& __fn, _Args&&... __args);
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
@@ -727,7 +733,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class promise<_Res>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
- friend future<typename result_of<_Fn(_Args...)>::type>
+ friend future<__async_result_of<_Fn, _Args...>>
async(launch, _Fn&&, _Args&&...);
typedef __basic_future<_Res> _Base_type;
@@ -770,7 +776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class promise<_Res&>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
- friend future<typename result_of<_Fn(_Args...)>::type>
+ friend future<__async_result_of<_Fn, _Args...>>
async(launch, _Fn&&, _Args&&...);
typedef __basic_future<_Res&> _Base_type;
@@ -813,7 +819,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class promise<void>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
- friend future<typename result_of<_Fn(_Args...)>::type>
+ friend future<__async_result_of<_Fn, _Args...>>
async(launch, _Fn&&, _Args&&...);
typedef __basic_future<void> _Base_type;
@@ -1699,10 +1705,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// async
template<typename _Fn, typename... _Args>
- future<typename result_of<_Fn(_Args...)>::type>
+ future<__async_result_of<_Fn, _Args...>>
async(launch __policy, _Fn&& __fn, _Args&&... __args)
{
- typedef typename result_of<_Fn(_Args...)>::type result_type;
std::shared_ptr<__future_base::_State_base> __state;
if ((__policy & launch::async) == launch::async)
{
@@ -1714,16 +1719,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__state = __future_base::_S_make_deferred_state(std::__bind_simple(
std::forward<_Fn>(__fn), std::forward<_Args>(__args)...));
}
- return future<result_type>(__state);
+ return future<__async_result_of<_Fn, _Args...>>(__state);
}
/// async, potential overload
template<typename _Fn, typename... _Args>
- inline future<typename result_of<_Fn(_Args...)>::type>
+ inline future<__async_result_of<_Fn, _Args...>>
async(_Fn&& __fn, _Args&&... __args)
{
- return async(launch::async|launch::deferred, std::forward<_Fn>(__fn),
- std::forward<_Args>(__args)...);
+ return std::async(launch::async|launch::deferred,
+ std::forward<_Fn>(__fn),
+ std::forward<_Args>(__args)...);
}
#endif // _GLIBCXX_ASYNC_ABI_COMPAT
diff --git a/libstdc++-v3/testsuite/30_threads/async/lwg2021.cc b/libstdc++-v3/testsuite/30_threads/async/lwg2021.cc
new file mode 100644
index 0000000..0c0ac3b
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/async/lwg2021.cc
@@ -0,0 +1,42 @@
+// Copyright (C) 2015 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/>.
+
+// { dg-do compile { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } }
+// { dg-options " -std=gnu++11 -pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } }
+// { dg-options " -std=gnu++11 -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++11 " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// LWG 2021. Further incorrect usages of result_of
+// Arguments to result_of should use decay.
+
+#include <future>
+
+struct A
+{
+ int operator()(int&&)&& { return 0; }
+ void operator()(int&)& { }
+};
+
+int main()
+{
+ A a;
+ int i = 0;
+ std::future<int> f = std::async(a, i);
+}