From a0e1dcd44f9c0ee22f56b73660f36072633adb69 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 15 Nov 2019 14:38:59 +0000 Subject: [PATCH] libstdc++: Fix definition of std::nostopstate object Also add header to PCH and Doxygen config. * doc/doxygen/user.cfg.in: Add . * include/precompiled/stdc++.h: Likewise. * include/std/stop_token: Fix definition of std::nostopstate. * testsuite/30_threads/headers/stop_token/synopsis.cc: New test. * testsuite/30_threads/headers/thread/types_std_c++20.cc: New test. * testsuite/30_threads/stop_token/stop_source.cc: New test. * testsuite/30_threads/stop_token/stop_token.cc: Remove unnecessary dg-require directives. Remove I/O and inclusion of . From-SVN: r278296 --- libstdc++-v3/ChangeLog | 11 +++ libstdc++-v3/doc/doxygen/user.cfg.in | 1 + libstdc++-v3/include/precompiled/stdc++.h | 1 + libstdc++-v3/include/std/stop_token | 2 +- .../30_threads/headers/stop_token/synopsis.cc | 35 +++++++++ .../headers/thread/types_std_c++20.cc | 30 ++++++++ .../30_threads/stop_token/stop_source.cc | 75 +++++++++++++++++++ .../30_threads/stop_token/stop_token.cc | 8 +- 8 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 libstdc++-v3/testsuite/30_threads/headers/stop_token/synopsis.cc create mode 100644 libstdc++-v3/testsuite/30_threads/headers/thread/types_std_c++20.cc create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/stop_source.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b537c956bdd..53f3b2961c8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2019-11-15 Jonathan Wakely + + * doc/doxygen/user.cfg.in: Add . + * include/precompiled/stdc++.h: Likewise. + * include/std/stop_token: Fix definition of std::nostopstate. + * testsuite/30_threads/headers/stop_token/synopsis.cc: New test. + * testsuite/30_threads/headers/thread/types_std_c++20.cc: New test. + * testsuite/30_threads/stop_token/stop_source.cc: New test. + * testsuite/30_threads/stop_token/stop_token.cc: Remove unnecessary + dg-require directives. Remove I/O and inclusion of . + 2019-11-14 Thomas Rodgers * include/Makefile.am: Add header. diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in b/libstdc++-v3/doc/doxygen/user.cfg.in index 18994703f0b..19f8ffd8230 100644 --- a/libstdc++-v3/doc/doxygen/user.cfg.in +++ b/libstdc++-v3/doc/doxygen/user.cfg.in @@ -840,6 +840,7 @@ INPUT = @srcdir@/doc/doxygen/doxygroups.cc \ include/sstream \ include/stack \ include/stdexcept \ + include/stop_token \ include/streambuf \ include/string \ include/string_view \ diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h index 118fc8f359a..c77136ef441 100644 --- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -140,6 +140,7 @@ #include #include #include +#include // #include #include #endif diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token index af64018bb0e..f96c267f22e 100644 --- a/libstdc++-v3/include/std/stop_token +++ b/libstdc++-v3/include/std/stop_token @@ -47,7 +47,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class stop_callback; struct nostopstate_t { explicit nostopstate_t() = default; }; - inline constexpr nostopstate_t nostopstate(); + inline constexpr nostopstate_t nostopstate{}; class stop_token { diff --git a/libstdc++-v3/testsuite/30_threads/headers/stop_token/synopsis.cc b/libstdc++-v3/testsuite/30_threads/headers/stop_token/synopsis.cc new file mode 100644 index 00000000000..b185bc7be39 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/headers/stop_token/synopsis.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2019 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 +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +namespace std +{ + class stop_token; + class stop_source; + struct nostopstate_t; + template + class stop_callback; +} + +namespace gnu +{ + constexpr const std::nostopstate_t* tag = &std::nostopstate; +} diff --git a/libstdc++-v3/testsuite/30_threads/headers/thread/types_std_c++20.cc b/libstdc++-v3/testsuite/30_threads/headers/thread/types_std_c++20.cc new file mode 100644 index 00000000000..86f29d8b001 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/headers/thread/types_std_c++20.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// { dg-require-gthreads "" } + +// Copyright (C) 2019 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 + +void test01() +{ + using t_t = std::thread; + using j_t = std::jthread; + + using namespace std::this_thread; +} diff --git a/libstdc++-v3/testsuite/30_threads/stop_token/stop_source.cc b/libstdc++-v3/testsuite/30_threads/stop_token/stop_source.cc new file mode 100644 index 00000000000..9e477b7d7ee --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/stop_token/stop_source.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2019 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 +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +#include +#include + +void +test01() +{ + std::stop_source ssrc; + VERIFY( ssrc.stop_possible() ); + VERIFY( !ssrc.stop_requested() ); + + std::stop_source copy(ssrc); + VERIFY( copy.stop_possible() ); + VERIFY( !copy.stop_requested() ); + VERIFY( ssrc.stop_possible() ); + VERIFY( !ssrc.stop_requested() ); + + std::stop_source move(std::move(ssrc)); + VERIFY( move.stop_possible() ); + VERIFY( !move.stop_requested() ); + VERIFY( copy.stop_possible() ); + VERIFY( !copy.stop_requested() ); + VERIFY( !ssrc.stop_possible() ); + VERIFY( !ssrc.stop_requested() ); +} + +void +test02() +{ + // stop_source(nostopstate_t) constructor is explicit: + static_assert(!std::is_convertible_v); + + std::stop_source ssrc(std::nostopstate); + VERIFY( !ssrc.stop_possible() ); + VERIFY( !ssrc.stop_requested() ); + + std::stop_source copy(ssrc); + VERIFY( !copy.stop_possible() ); + VERIFY( !copy.stop_requested() ); + VERIFY( !ssrc.stop_possible() ); + VERIFY( !ssrc.stop_requested() ); + + std::stop_source move(std::move(ssrc)); + VERIFY( !move.stop_possible() ); + VERIFY( !move.stop_requested() ); + VERIFY( !copy.stop_possible() ); + VERIFY( !copy.stop_requested() ); + VERIFY( !ssrc.stop_possible() ); + VERIFY( !ssrc.stop_requested() ); +} + +int main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc b/libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc index 37d79e8a64e..f0772c1d80f 100644 --- a/libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc +++ b/libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc @@ -15,13 +15,10 @@ // with this library; see the file COPYING3. If not see // . -// { dg-options "-std=gnu++2a -pthread" } -// { dg-do run } -// { dg-require-effective-target c++2a } -// { dg-require-effective-target pthread } +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } #include -#include #include int main() @@ -41,7 +38,6 @@ int main() // register callback bool cb1called{false}; auto cb1 = [&]{ - std::cout << "cb1" << std::endl; cb1called = true; }; { -- 2.30.2