[PATCH] libstdc++: Add c++2a <syncstream>

Jonathan Wakely jwakely@redhat.com
Thu Oct 29 16:18:14 GMT 2020


On 21/10/20 09:53 -0700, Thomas Rodgers wrote:
>From: Thomas Rodgers <trodgers@redhat.com>
>
>libstdc++/Changelog:
>	libstdc++-v3/doc/doxygen/user.cfg.in (INPUT): Add new header.
>	libstdc++-v3/include/Makefile.am (std_headers): Add new header.
>	libstdc++-v3/include/Makefile.in: Regenerate.
>	libstdc++-v3/include/precompiled/stdc++.h: Include new header.
>	libstdc++-v3/include/std/streambuf
>        (__detail::__streambuf_core_access): Define.
>        (basic_streambuf): Befriend __detail::__streambuf_core_access.
>	libstdc++-v3/include/std/syncstream: New header.
>	libstdc++-v3/include/std/version: Add __cpp_lib_syncbuf:
>	libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc: New test.
>	libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc: Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
>        Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc:
>        Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
>        Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc: Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc: Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc:
>        Likewise.
>	libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc:
>        Likewise.
>
>---
> libstdc++-v3/doc/doxygen/user.cfg.in          |   1 +
> libstdc++-v3/include/Makefile.am              |   1 +
> libstdc++-v3/include/Makefile.in              |   1 +
> libstdc++-v3/include/precompiled/stdc++.h     |   2 +-
> libstdc++-v3/include/std/syncstream           | 279 ++++++++++++++++++
> libstdc++-v3/include/std/version              |   4 +
> .../testsuite/27_io/basic_syncbuf/1.cc        |  28 ++
> .../testsuite/27_io/basic_syncbuf/2.cc        |  27 ++
> .../27_io/basic_syncbuf/basic_ops/1.cc        | 138 +++++++++
> .../27_io/basic_syncbuf/requirements/types.cc |  42 +++
> .../27_io/basic_syncbuf/sync_ops/1.cc         | 130 ++++++++
> .../testsuite/27_io/basic_syncstream/1.cc     |  28 ++
> .../testsuite/27_io/basic_syncstream/2.cc     |  27 ++
> .../27_io/basic_syncstream/basic_ops/1.cc     | 135 +++++++++
> .../basic_syncstream/requirements/types.cc    |  43 +++
> 15 files changed, 885 insertions(+), 1 deletion(-)
> create mode 100644 libstdc++-v3/include/std/syncstream
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc
> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc
>
>diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in b/libstdc++-v3/doc/doxygen/user.cfg.in
>index 9b49a15d31b..320f6dea688 100644
>--- a/libstdc++-v3/doc/doxygen/user.cfg.in
>+++ b/libstdc++-v3/doc/doxygen/user.cfg.in
>@@ -897,6 +897,7 @@ INPUT                  = @srcdir@/doc/doxygen/doxygroups.cc \
>                          include/streambuf \
>                          include/string \
>                          include/string_view \
>+                         include/syncstream \
>                          include/system_error \
>                          include/thread \
>                          include/tuple \
>diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
>index 28d273924ee..61aaff7a2f4 100644
>--- a/libstdc++-v3/include/Makefile.am
>+++ b/libstdc++-v3/include/Makefile.am
>@@ -73,6 +73,7 @@ std_headers = \
> 	${std_srcdir}/shared_mutex \
> 	${std_srcdir}/span \
> 	${std_srcdir}/sstream \
>+	${std_srcdir}/syncstream \
> 	${std_srcdir}/stack \
> 	${std_srcdir}/stdexcept \
> 	${std_srcdir}/stop_token \
>diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h
>index 7518a98c25a..8899c323a28 100644
>--- a/libstdc++-v3/include/precompiled/stdc++.h
>+++ b/libstdc++-v3/include/precompiled/stdc++.h
>@@ -141,6 +141,6 @@
> #include <ranges>
> #include <span>
> #include <stop_token>
>-// #include <syncstream>
>+#include <syncstream>
> #include <version>
> #endif
>diff --git a/libstdc++-v3/include/std/syncstream b/libstdc++-v3/include/std/syncstream
>new file mode 100644
>index 00000000000..3f78cef1d8d
>--- /dev/null
>+++ b/libstdc++-v3/include/std/syncstream
>@@ -0,0 +1,279 @@
>+// <syncstream> -*- C++ -*-
>+
>+// Copyright (C) 2020 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.
>+
>+// Under Section 7 of GPL version 3, you are granted additional
>+// permissions described in the GCC Runtime Library Exception, version
>+// 3.1, as published by the Free Software Foundation.
>+
>+// You should have received a copy of the GNU General Public License and
>+// a copy of the GCC Runtime Library Exception along with this program;
>+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>+// <http://www.gnu.org/licenses/>.
>+
>+/** @file include/syncstream
>+ *  This is a Standard C++ Library header.
>+ */
>+
>+ #ifndef _GLIBCXX_SYNCSTREAM
>+ #define _GLIBCXX_SYNCSTREAM 1

These two lines are indented one column, they shouldn't be.

>+
>+#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI

The _GLIBCXX_USE_CXX11_ABI check needs to come after including at
least one libstdc++ header, because otherwise it's not been set yet.
It gets set to a default value in <bits/c++config.h> so if you check
it before that (or any other header that includes it) has been
included, then it won't be defined.

As discussed, either the entire header needs to be guarded with
#ifdef _GLIBCXX_HAS_GTHREADS or the uses of the mutex need to be
guarded by that (making it usable without threads, even though it does
no synchronization).

>diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
>index d5d42ed0a72..5542d51087e 100644
>--- a/libstdc++-v3/include/std/version
>+++ b/libstdc++-v3/include/std/version
>@@ -226,6 +226,10 @@
> #define __cpp_lib_span 202002L
> #define __cpp_lib_ssize 201902L
> #define __cpp_lib_starts_ends_with 201711L
>+# ifdef _GLIBCXX_USE_CXX11_ABI

This should be #if not #ifdef, otherwise the  condition is true for
_GLIBCXX_USE_CXX11_ABI=0 as wekk as _GLIBCXX_USE_CXX11_ABI=1

>+// Only supported with cx11-abi
>+#  define __cpp_lib_syncbuf 201803L
>+# endif
> #define __cpp_lib_to_address 201711L
> #define __cpp_lib_to_array 201907L
> #endif

Also several of the tests still do:

#elif __cpp_lib_syncbuf!= 201803L

with no space before the operator.



More information about the Gcc-patches mailing list