aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-02-23 23:23:43 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2018-02-23 23:23:43 +0000
commitcc535146720889c8e32712b0351204ee182d4843 (patch)
tree7271bee4a1eb11e0b500e4c1bd45cdb26334f103 /libstdc++-v3
parent8af2826bb0cd48d90dc04fc044a9ddbf978a5281 (diff)
downloadgcc-cc535146720889c8e32712b0351204ee182d4843.zip
gcc-cc535146720889c8e32712b0351204ee182d4843.tar.gz
gcc-cc535146720889c8e32712b0351204ee182d4843.tar.bz2
PR libstdc++/84532 prevent unwrapping of reference_wrapper arguments
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/std/thread15
-rw-r--r--libstdc++-v3/testsuite/30_threads/async/84532.cc38
-rw-r--r--libstdc++-v3/testsuite/30_threads/thread/84532.cc38
4 files changed, 90 insertions, 9 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index a0bee0e..4f83772 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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]
diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 0c53294..1cabd6a 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -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
index 0000000..480ed73
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/async/84532.cc
@@ -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
index 0000000..f389b9b
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/84532.cc
@@ -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));