libstdc++: Fix definition of std::nostopstate object
authorJonathan Wakely <jwakely@redhat.com>
Fri, 15 Nov 2019 14:38:59 +0000 (14:38 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 15 Nov 2019 14:38:59 +0000 (14:38 +0000)
Also add <stop_token> header to PCH and Doxygen config.

* doc/doxygen/user.cfg.in: Add <stop_token>.
* 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 <iostream>.

From-SVN: r278296

libstdc++-v3/ChangeLog
libstdc++-v3/doc/doxygen/user.cfg.in
libstdc++-v3/include/precompiled/stdc++.h
libstdc++-v3/include/std/stop_token
libstdc++-v3/testsuite/30_threads/headers/stop_token/synopsis.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/headers/thread/types_std_c++20.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/stop_token/stop_source.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc

index b537c956bdd4fc78519e324df66fcfd13527d672..53f3b2961c867d0de088c0c0329949cbd08b9b3c 100644 (file)
@@ -1,3 +1,14 @@
+2019-11-15  Jonathan Wakely  <jwakely@redhat.com>
+
+       * doc/doxygen/user.cfg.in: Add <stop_token>.
+       * 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 <iostream>.
+
 2019-11-14  Thomas Rodgers  <trodgers@redhat.com>
 
        * include/Makefile.am: Add <stop_token> header.
index 18994703f0bf43aefb020420aeecdb058464cc3f..19f8ffd823082a92a7bf57b47e36c2ba36e35670 100644 (file)
@@ -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 \
index 118fc8f359a84f0e9f16785fdfc76447aba11bbe..c77136ef44165df513505098e9adfc9049d4014c 100644 (file)
 #include <numbers>
 #include <ranges>
 #include <span>
+#include <stop_token>
 // #include <syncstream>
 #include <version>
 #endif
index af64018bb0e34b02006216542b84fbce57af30fa..f96c267f22e7784a3ee114b854de6d9bdf1183d6 100644 (file)
@@ -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 (file)
index 0000000..b185bc7
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <stop_token>
+
+namespace std
+{
+  class stop_token;
+  class stop_source;
+  struct nostopstate_t;
+  template<class>
+    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 (file)
index 0000000..86f29d8
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+#include <thread>
+
+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 (file)
index 0000000..9e477b7
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <stop_token>
+#include <testsuite_hooks.h>
+
+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::nostopstate_t, std::stop_source>);
+
+  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();
+}
index 37d79e8a64e953e8fd73c73363d542e2a7b5779c..f0772c1d80fb10f78a4c204f3c2c4d6dabf34a08 100644 (file)
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { 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 <stop_token>
-#include <iostream>
 #include <testsuite_hooks.h>
 
 int main()
@@ -41,7 +38,6 @@ int main()
   // register callback
   bool cb1called{false};
   auto cb1 = [&]{
-               std::cout << "cb1" << std::endl;
                cb1called = true;
              };
   {