aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/30_threads
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-08-22 15:42:17 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-08-22 22:52:24 +0100
commit5abe0657553580bd1b7488dd84d55138a8d9f23c (patch)
treea5841e9abbf074b0f1cd9dd4f9ed57e048a3fd9d /libstdc++-v3/testsuite/30_threads
parent1b09eea33f2bf9d1eae73b25cc25efb05ea1dc3f (diff)
downloadgcc-5abe0657553580bd1b7488dd84d55138a8d9f23c.zip
gcc-5abe0657553580bd1b7488dd84d55138a8d9f23c.tar.gz
gcc-5abe0657553580bd1b7488dd84d55138a8d9f23c.tar.bz2
libstdc++: Fix for explicit copy ctors in <thread> and <future> [PR106695]
When I changed std::thread and std::async to avoid unnecessary move construction of temporaries, I introduced a regression where types with an explicit copy constructor could not be passed to std::thread or std::async. The fix is to add a constructor instead of using aggregate initialization of an unnamed temporary. libstdc++-v3/ChangeLog: PR libstdc++/106695 * include/bits/std_thread.h (thread::_State_impl): Forward individual arguments to _Invoker constructor. (thread::_Invoker): Add constructor. Delete copies. * include/std/future (__future_base::_Deferred_state): Forward individual arguments to _Invoker constructor. (__future_base::_Async_state_impl): Likewise. * testsuite/30_threads/async/106695.cc: New test. * testsuite/30_threads/thread/106695.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/30_threads')
-rw-r--r--libstdc++-v3/testsuite/30_threads/async/106695.cc29
-rw-r--r--libstdc++-v3/testsuite/30_threads/thread/106695.cc21
2 files changed, 50 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/30_threads/async/106695.cc b/libstdc++-v3/testsuite/30_threads/async/106695.cc
new file mode 100644
index 0000000..7499634
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/async/106695.cc
@@ -0,0 +1,29 @@
+// { dg-do compile { target c++11 } }
+// { dg-require-gthreads "" }
+
+// PR libstdc++/106695
+// Explicit copy constructor does not work for a parameter passed via std::async
+
+#include <future>
+
+struct A {
+ A() = default;
+ explicit A(const A&) = default;
+};
+
+void func(const A&) { }
+
+void
+test_async()
+{
+ (void) std::async(std::launch::async, func, A{});
+ (void) std::async(std::launch::deferred, func, A{});
+ (void) std::async(func, A{});
+}
+
+void
+test_task()
+{
+ std::packaged_task<void(const A&)> task(func);
+ task(A{});
+}
diff --git a/libstdc++-v3/testsuite/30_threads/thread/106695.cc b/libstdc++-v3/testsuite/30_threads/thread/106695.cc
new file mode 100644
index 0000000..97e9e92
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/106695.cc
@@ -0,0 +1,21 @@
+// { dg-do compile { target c++11 } }
+// { dg-require-gthreads "" }
+
+// PR libstdc++/106695
+// Explicit copy constructor does not work for a parameter passed via std::async
+
+#include <thread>
+
+struct A {
+ A() = default;
+ explicit A(const A&) = default;
+};
+
+void func(const A&) { }
+
+void
+test_thread()
+{
+ std::thread t(func, A{});
+ t.join();
+}