PR libstdc++/84532 prevent unwrapping of reference_wrapper arguments
authorJonathan Wakely <jwakely@redhat.com>
Fri, 23 Feb 2018 23:23:43 +0000 (23:23 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 23 Feb 2018 23:23:43 +0000 (23:23 +0000)
PR libstdc++/84532
* include/std/thread (thread::__make_invoker): Construct tuple
directly instead of using make_tuple.
* testsuite/30_threads/async/84532.cc: New.
* testsuite/30_threads/thread/84532.cc: New.

From-SVN: r257956

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/thread
libstdc++-v3/testsuite/30_threads/async/84532.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/thread/84532.cc [new file with mode: 0644]

index a0bee0e048a7775b484e4eb318628f6a7cb39aee..4f83772b47911c80ad3f1e0109335944e70983eb 100644 (file)
@@ -1,3 +1,11 @@
+2018-02-23  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/84532
+       * include/std/thread (thread::__make_invoker): Construct tuple
+       directly instead of using make_tuple.
+       * testsuite/30_threads/async/84532.cc: New.
+       * testsuite/30_threads/thread/84532.cc: New.
+
 2018-02-20  François Dumont  <fdumont@gcc.gnu.org>
 
        * include/ext/aligned_buffer.h [_GLIBCXX_INLINE_VERSION]
index 0c53294aac299982ac8a693b932aae98ac69f39c..1cabd6ae0e66365507cf4e5be3e6f84d19452e45 100644 (file)
@@ -243,21 +243,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        { return _M_invoke(_Indices()); }
       };
 
-    // Alias for _Invoker<tuple<DECAY_COPY(_Tp)...>>
     template<typename... _Tp>
-      using __invoker_type
-       = _Invoker<decltype(std::make_tuple(std::declval<_Tp>()...))>;
+      using __decayed_tuple = tuple<typename std::decay<_Tp>::type...>;
 
   public:
-    // Returns a call wrapper that does
-    // INVOKE(DECAY_COPY(__callable), DECAY_COPY(__args)).
+    // Returns a call wrapper that stores
+    // tuple{DECAY_COPY(__callable), DECAY_COPY(__args)...}.
     template<typename _Callable, typename... _Args>
-      static __invoker_type<_Callable, _Args...>
+      static _Invoker<__decayed_tuple<_Callable, _Args...>>
       __make_invoker(_Callable&& __callable, _Args&&... __args)
       {
-       return { {
-           std::make_tuple(std::forward<_Callable>(__callable),
-                           std::forward<_Args>(__args)...)
+       return { __decayed_tuple<_Callable, _Args...>{
+           std::forward<_Callable>(__callable), std::forward<_Args>(__args)...
        } };
       }
   };
diff --git a/libstdc++-v3/testsuite/30_threads/async/84532.cc b/libstdc++-v3/testsuite/30_threads/async/84532.cc
new file mode 100644 (file)
index 0000000..480ed73
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-do compile { target c++11 } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2018 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>
+
+// PR libstdc++/84532
+
+struct F
+{
+  template<typename T, typename U>
+    void operator()(T, U, int&)
+    {
+      using std::is_same;
+      using std::reference_wrapper;
+      static_assert(is_same<T, reference_wrapper<int>>::value, "");
+      static_assert(is_same<U, reference_wrapper<const int>>::value, "");
+    }
+};
+int i = 0;
+auto fut = std::async(F{}, std::ref(i), std::cref(i), std::ref(i));
diff --git a/libstdc++-v3/testsuite/30_threads/thread/84532.cc b/libstdc++-v3/testsuite/30_threads/thread/84532.cc
new file mode 100644 (file)
index 0000000..f389b9b
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-do compile { target c++11 } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2018 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 <thread>
+
+// PR libstdc++/84532
+
+struct F
+{
+  template<typename T, typename U>
+    void operator()(T, U, int&)
+    {
+      using std::is_same;
+      using std::reference_wrapper;
+      static_assert(is_same<T, reference_wrapper<int>>::value, "");
+      static_assert(is_same<U, reference_wrapper<const int>>::value, "");
+    }
+};
+int i = 0;
+std::thread t(F{}, std::ref(i), std::cref(i), std::ref(i));