future (__async_result_of): New alias template.
authorJonathan Wakely <jwakely@redhat.com>
Fri, 29 May 2015 13:44:52 +0000 (14:44 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 29 May 2015 13:44:52 +0000 (14:44 +0100)
* 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

libstdc++-v3/ChangeLog
libstdc++-v3/doc/xml/manual/intro.xml
libstdc++-v3/include/std/future
libstdc++-v3/testsuite/30_threads/async/lwg2021.cc [new file with mode: 0644]

index 94c7963eea763c2a4b19584d5664c1288bc7a8e0..9b53161ac4cbcabf0e44f45aa494312db3ebc353 100644 (file)
@@ -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.
index b52108956874091d60911937fef553f2fba40234..f0c66a222662c7fcd1f22359d6b515b91ab80aba 100644 (file)
@@ -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>
index c4baf90622aa1e996726ae7593eee70a6829f595..216a921796af4e2f99ffc4a43d6ba58f5eff95d0 100644 (file)
@@ -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 (file)
index 0000000..0c0ac3b
--- /dev/null
@@ -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);
+}