From cc535146720889c8e32712b0351204ee182d4843 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 23 Feb 2018 23:23:43 +0000 Subject: [PATCH] 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 --- libstdc++-v3/ChangeLog | 8 ++++ libstdc++-v3/include/std/thread | 15 +++----- .../testsuite/30_threads/async/84532.cc | 38 +++++++++++++++++++ .../testsuite/30_threads/thread/84532.cc | 38 +++++++++++++++++++ 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 libstdc++-v3/testsuite/30_threads/async/84532.cc create mode 100644 libstdc++-v3/testsuite/30_threads/thread/84532.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a0bee0e048a..4f83772b479 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2018-02-23 Jonathan Wakely + + 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 * include/ext/aligned_buffer.h [_GLIBCXX_INLINE_VERSION] diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 0c53294aac2..1cabd6ae0e6 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> template - using __invoker_type - = _Invoker()...))>; + using __decayed_tuple = tuple::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 - 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 00000000000..480ed733ca3 --- /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 +// . + +#include + +// PR libstdc++/84532 + +struct F +{ + template + void operator()(T, U, int&) + { + using std::is_same; + using std::reference_wrapper; + static_assert(is_same>::value, ""); + static_assert(is_same>::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 00000000000..f389b9b88e3 --- /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 +// . + +#include + +// PR libstdc++/84532 + +struct F +{ + template + void operator()(T, U, int&) + { + using std::is_same; + using std::reference_wrapper; + static_assert(is_same>::value, ""); + static_assert(is_same>::value, ""); + } +}; +int i = 0; +std::thread t(F{}, std::ref(i), std::cref(i), std::ref(i)); -- 2.30.2