diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/30_threads/thread/cons | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/30_threads/thread/cons')
12 files changed, 819 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc new file mode 100644 index 000000000..94f1d7db4 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc @@ -0,0 +1,52 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2008, 2009 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> +#include <system_error> +#include <testsuite_hooks.h> + +// thread default cons works +// thread default cons no throw +// thread default cons not joinable +int main() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t; + VERIFY( !t.joinable() ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc new file mode 100644 index 000000000..87b4476f6 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc @@ -0,0 +1,73 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2008, 2009 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 <functional> // std::ref +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +void +free_function(std::thread::id& id) +{ + id = std::this_thread::get_id(); +} + +// thread::id default cons +// thread::id copy ctor +// thread variadic cons, c++ function +// thread variadic cons joinable +// thread join +// thread join postcondition not joinable +// thread join postcondition function called correctly +// this_thread::get_id +void test02() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread::id id1; + std::thread t(free_function, std::ref(id1)); + std::thread::id id2 = t.get_id(); + VERIFY( t.joinable() ); + t.join(); + VERIFY( !t.joinable() ); + VERIFY( id1 == id2 ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc new file mode 100644 index 000000000..b35f28eea --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc @@ -0,0 +1,92 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2008, 2009 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 <functional> // std::unary_function, std::ref +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +struct copyable : public std::unary_function<std::thread::id&, void> +{ + copyable() = default; + ~copyable() = default; + copyable(const copyable& c) + { ++copy_count; } + + void operator()(std::thread::id& id) const + { + id = std::this_thread::get_id(); + } + + static int copy_count; +}; + +int copyable::copy_count = 0; + +// same as 2, but function is copyable function object +// thread variadic cons not copied when std::ref +// thread variadic cons copied when not std::ref +// no errors +void test03() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread::id t1_id1; + copyable c1; + std::thread t1(std::ref(c1), std::ref(t1_id1)); + std::thread::id t1_id2 = t1.get_id(); + VERIFY( t1.joinable() ); + t1.join(); + VERIFY( !t1.joinable() ); + VERIFY( t1_id1 == t1_id2 ); + VERIFY( copyable::copy_count == 0 ); + + std::thread::id t2_id1; + copyable c2; + std::thread t2(c2, std::ref(t2_id1)); + std::thread::id t2_id2 = t2.get_id(); + VERIFY( t2.joinable() ); + t2.join(); + VERIFY( !t2.joinable() ); + VERIFY( t2_id1 == t2_id2 ); + VERIFY( copyable::copy_count > 0 ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc new file mode 100644 index 000000000..982a49b05 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc @@ -0,0 +1,87 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2008, 2009 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 <functional> // std::unary_function, std::ref, std::cref +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +struct noncopyable : std::unary_function<std::thread::id&, void> +{ + noncopyable() = default; + ~noncopyable() = default; + noncopyable(const noncopyable&) = delete; + noncopyable& operator=(const noncopyable&) = delete; + void operator()(std::thread::id& id) const + { + id = std::this_thread::get_id(); + } +}; + +// same as 3, but function is noncopyable function object +// thread variadic cons not copied when std::ref +// thread variadic cons copied when not std::ref +// thread variadic cons not copied when std::cref +// thread variadic cons copied when not std::cref +// no errors +void test03() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread::id t1_id1; + noncopyable nc1; + std::thread t1(std::ref(nc1), std::ref(t1_id1)); + std::thread::id t1_id2 = t1.get_id(); + VERIFY( t1.joinable() ); + t1.join(); + VERIFY( !t1.joinable() ); + VERIFY( t1_id1 == t1_id2 ); + + std::thread::id t2_id1; + noncopyable nc2; + std::thread t2(std::cref(nc2), std::ref(t2_id1)); + std::thread::id t2_id2 = t2.get_id(); + VERIFY( t2.joinable() ); + t2.join(); + VERIFY( !t2.joinable() ); + VERIFY( t2_id1 == t2_id2 ); + } + catch(const std::system_error&) + { + VERIFY( false ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/5.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/5.cc new file mode 100644 index 000000000..000e558c9 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/5.cc @@ -0,0 +1,77 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009 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 <functional> // std::unary_function, std::ref +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +struct nonconst : public std::unary_function<std::thread::id&, void> +{ + void operator()(std::thread::id& id) + { + id = std::this_thread::get_id(); + } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread::id t1_id1; + nonconst c1; + std::thread t1(std::ref(c1), std::ref(t1_id1)); + std::thread::id t1_id2 = t1.get_id(); + VERIFY( t1.joinable() ); + t1.join(); + VERIFY( !t1.joinable() ); + VERIFY( t1_id1 == t1_id2 ); + + std::thread::id t2_id1; + nonconst c2; + std::thread t2(c2, std::ref(t2_id1)); + std::thread::id t2_id2 = t2.get_id(); + VERIFY( t2.joinable() ); + t2.join(); + VERIFY( !t2.joinable() ); + VERIFY( t2_id1 == t2_id2 ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc new file mode 100644 index 000000000..b21892cd8 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc @@ -0,0 +1,65 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009 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> +#include <system_error> +#include <testsuite_hooks.h> + +bool f_was_called = false; + +void f() +{ + f_was_called = true; +} + +// thread non-variadic cons, c++ function +// thread join +// thread join postcondition function called correctly +// no errors +void test06() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t(f); + t.join(); + VERIFY( f_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc new file mode 100644 index 000000000..5aa4c32a2 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc @@ -0,0 +1,72 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2008, 2009 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> +#include <system_error> +#include <testsuite_hooks.h> + +bool functor_was_called = false; + +struct copyable +{ + copyable() = default; + ~copyable() = default; + copyable(const copyable& c) = default; + copyable& operator=(const copyable&) = default; + + void operator()() const + { + functor_was_called = true; + } +}; + +// same as 6, but function is copyable function object passed by reference +void test07() +{ + bool test __attribute__((unused)) = true; + + try + { + copyable c; + copyable& rc = c; + std::thread t(rc); + t.join(); + VERIFY( functor_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc new file mode 100644 index 000000000..b0ed1eda1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc @@ -0,0 +1,72 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2008, 2009 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> +#include <system_error> +#include <testsuite_hooks.h> + +bool functor_was_called = false; + +struct moveable +{ + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } + + void operator()() const + { + functor_was_called = true; + } +}; + +// same as 6, but function object is movable +void test08() +{ + bool test __attribute__((unused)) = true; + + try + { + moveable m; + std::thread t(std::move(m)); + t.join(); + VERIFY( functor_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/9.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/9.cc new file mode 100644 index 000000000..04394b262 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/9.cc @@ -0,0 +1,83 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009 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> +#include <system_error> +#include <testsuite_hooks.h> + +int total = 0; + +// Functor has internal state. +struct moveable +{ + int i; + + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + + moveable(int j): i(j) { } + moveable(moveable&& m): i(m.i) { } + + void operator()() const { total += i; } +}; + +// Two threads called by same functor type, different functor objects +// that have different state. Make sure each thread calls the correct +// functor. +void test09() +{ + bool test __attribute__((unused)) = true; + + try + { + // first + moveable m1(60); + std::thread t1(std::move(m1)); + t1.join(); + VERIFY( total == 60 ); + + // second + moveable m2(600); + std::thread t2(std::move(m2)); + t2.join(); + VERIFY( total == 660 ); // Not 120... + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/assign_neg.cc new file mode 100644 index 000000000..406d16085 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/assign_neg.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009, 2010 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> + +void test01() +{ + // assign + typedef std::thread test_type; + test_type t1; + test_type t2; + t1 = t2; // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/copy_neg.cc new file mode 100644 index 000000000..9d8681d47 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/copy_neg.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009, 2010 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> + +void test01() +{ + // copy + typedef std::thread test_type; + test_type t1; + test_type t2(t1); // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc new file mode 100644 index 000000000..f3f5c7baf --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc @@ -0,0 +1,79 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009 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> +#include <utility> +#include <testsuite_hooks.h> + +bool functor_was_called = false; + +struct moveable +{ + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } + + void operator()() const { } +}; + + +void test01() +{ + bool test __attribute__((unused)) = true; + + moveable m; + std::thread b(std::move(m)); + std::thread::id id_initial = b.get_id(); + VERIFY( b.joinable() ); + VERIFY( id_initial != std::thread::id() ); + + // copy move construct + // copied new thread old id, original thread default id + std::thread c(std::move(b)); + VERIFY( c.joinable() ); + VERIFY( c.get_id() == id_initial ); + VERIFY( !b.joinable() ); + VERIFY( b.get_id() == std::thread::id() ); + + // copy move assign + std::thread d; + VERIFY( !d.joinable() ); + VERIFY( d.get_id() == std::thread::id() ); + d = std::move(c); + VERIFY( d.joinable() ); + VERIFY( d.get_id() == id_initial ); + VERIFY( !c.joinable() ); + VERIFY( c.get_id() == std::thread::id() ); + + d.join(); +} + +int main(void) +{ + test01(); + return 0; +} |