From: Jonathan Wakely Date: Fri, 29 May 2015 13:44:52 +0000 (+0100) Subject: future (__async_result_of): New alias template. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=75eb64433edb2a48c471c50e729612a326d1b1e9;p=gcc.git 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 94c7963eea7..9b53161ac4c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2015-05-29 Jonathan Wakely + * 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::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 b5210895687..f0c66a22266 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. Return the end of the filled range. + 2021: + Further incorrect uses of result_of + + Correctly decay types in signature of std::async. + + diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index c4baf90622a..216a921796a 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 - future::type> + using __async_result_of = typename result_of< + typename decay<_Fn>::type(typename decay<_Args>::type...)>::type; + + template + future<__async_result_of<_Fn, _Args...>> async(launch __policy, _Fn&& __fn, _Args&&... __args); template - future::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 friend class packaged_task; template - friend future::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 friend class packaged_task; template - friend future::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; template friend class packaged_task; template - friend future::type> + friend future<__async_result_of<_Fn, _Args...>> async(launch, _Fn&&, _Args&&...); typedef __basic_future _Base_type; @@ -1699,10 +1705,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// async template - future::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(__state); + return future<__async_result_of<_Fn, _Args...>>(__state); } /// async, potential overload template - inline future::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 00000000000..0c0ac3b9e56 --- /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 +// . + +// { 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 + +struct A +{ + int operator()(int&&)&& { return 0; } + void operator()(int&)& { } +}; + +int main() +{ + A a; + int i = 0; + std::future f = std::async(a, i); +}