Skip to content

Commit 7cc72a0

Browse files
committed
Implement syncstream (p0053)
This patch implements `std::basic_syncbuf` and `std::basic_osyncstream` as specified in paper p0053r7. ~~For ease of reviewing I am submitting this patch before submitting a patch for `std::basic_osyncstream`. ~~ ~~Please note, this patch is not 100% complete. I plan on adding more tests (see comments), specifically I plan on adding tests for multithreading and synchronization.~~ Edit: I decided that it would be far easier for me to keep track of this and make changes that affect both `std::basic_syncbuf` and `std::basic_osyncstream` if both were in one patch. The patch was originally written by @zoecarver Implements - P0053R7 - C++ Synchronized Buffered Ostream - LWG-3127 basic_osyncstream::rdbuf needs a const_cast - LWG-3334 basic_osyncstream move assignment and destruction calls basic_syncbuf::emit() twice - LWG-3570 basic_osyncstream::emit should be an unformatted output function - LWG-3867 Should std::basic_osyncstream's move assignment operator be noexcept? Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D67086
1 parent f1b0a54 commit 7cc72a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3772
-27
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Status
286286
--------------------------------------------------- -----------------
287287
``__cpp_lib_string_view`` ``201803L``
288288
--------------------------------------------------- -----------------
289-
``__cpp_lib_syncbuf`` *unimplemented*
289+
``__cpp_lib_syncbuf`` ``201803L``
290290
--------------------------------------------------- -----------------
291291
``__cpp_lib_three_way_comparison`` *unimplemented*
292292
--------------------------------------------------- -----------------

libcxx/docs/ReleaseNotes/18.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Implemented Papers
4747
- P2443R1 - ``views::chunk_by``
4848
- P2538R1 - ADL-proof ``std::projected``
4949
- P2614R2 - Deprecate ``numeric_limits::has_denorm``
50+
- P0053R7 - C++ Synchronized Buffered Ostream (in the experimental library)
5051

5152

5253
Improvements and New Features

libcxx/docs/Status/Cxx20Issues.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"`3096 <https://wg21.link/LWG3096>`__","``path::lexically_relative``\ is confused by trailing slashes","San Diego","|Complete|",""
115115
"`3116 <https://wg21.link/LWG3116>`__","``OUTERMOST_ALLOC_TRAITS``\ needs ``remove_reference_t``\ ","San Diego","",""
116116
"`3122 <https://wg21.link/LWG3122>`__","``__cpp_lib_chrono_udls``\ was accidentally dropped","San Diego","|Complete|",""
117-
"`3127 <https://wg21.link/LWG3127>`__","``basic_osyncstream::rdbuf``\ needs a ``const_cast``\ ","San Diego","",""
117+
"`3127 <https://wg21.link/LWG3127>`__","``basic_osyncstream::rdbuf``\ needs a ``const_cast``\ ","San Diego","|Complete|","18.0"
118118
"`3128 <https://wg21.link/LWG3128>`__","``strstream::rdbuf``\ needs a ``const_cast``\ ","San Diego","|Nothing To Do|",""
119119
"`3129 <https://wg21.link/LWG3129>`__","``regex_token_iterator``\ constructor uses wrong pointer arithmetic","San Diego","",""
120120
"`3130 <https://wg21.link/LWG3130>`__","|sect|\ [input.output] needs many ``addressof``\ ","San Diego","",""
@@ -254,7 +254,7 @@
254254
"`3330 <https://wg21.link/LWG3330>`__","Include ``<compare>``\ from most library headers","Prague","|Complete|","13.0","|spaceship|"
255255
"`3331 <https://wg21.link/LWG3331>`__","Define ``totally_ordered/_with``\ in terms of ``partially-ordered-with``\ ","Prague","|Complete|","13.0"
256256
"`3332 <https://wg21.link/LWG3332>`__","Issue in |sect|\ [time.format]","Prague","|Complete|","16.0","|chrono| |format|"
257-
"`3334 <https://wg21.link/LWG3334>`__","``basic_osyncstream``\ move assignment and destruction calls ``basic_syncbuf::emit()``\ twice","Prague","",""
257+
"`3334 <https://wg21.link/LWG3334>`__","``basic_osyncstream``\ move assignment and destruction calls ``basic_syncbuf::emit()``\ twice","Prague","|Complete|","18.0"
258258
"`3335 <https://wg21.link/LWG3335>`__","Resolve C++20 NB comments US 273 and GB 274","Prague","|Complete|","15.0","|ranges|"
259259
"`3338 <https://wg21.link/LWG3338>`__","Rename ``default_constructible``\ to ``default_initializable``\ ","Prague","|Complete|","13.0"
260260
"`3340 <https://wg21.link/LWG3340>`__","Formatting functions should throw on argument/format string mismatch in |sect|\ [format.functions]","Prague","|Complete|","14.0","|format|"

libcxx/docs/Status/Cxx20Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"`P0674R1 <https://wg21.link/P0674R1>`__","LWG","Extending make_shared to Support Arrays","Toronto","|Complete|","15.0"
44
"","","","","","",""
55
"`P0020R6 <https://wg21.link/P0020R6>`__","LWG","Floating Point Atomic","Albuquerque","",""
6-
"`P0053R7 <https://wg21.link/P0053R7>`__","LWG","C++ Synchronized Buffered Ostream","Albuquerque","",""
6+
"`P0053R7 <https://wg21.link/P0053R7>`__","LWG","C++ Synchronized Buffered Ostream","Albuquerque","|Complete|","18.0"
77
"`P0202R3 <https://wg21.link/P0202R3>`__","LWG","Add constexpr modifiers to functions in <algorithm> and <utility> Headers","Albuquerque","|Complete|","12.0"
88
"`P0415R1 <https://wg21.link/P0415R1>`__","LWG","Constexpr for ``std::complex``\ ","Albuquerque","|Complete|","16.0"
99
"`P0439R0 <https://wg21.link/P0439R0>`__","LWG","Make ``std::memory_order``\ a scoped enumeration","Albuquerque","|Complete|",""

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
`3566 <https://wg21.link/LWG3566>`__,"Constraint recursion for ``operator<=>(optional<T>, U)``","October 2021","|Complete|","17.0","|spaceship|"
123123
`3567 <https://wg21.link/LWG3567>`__,"Formatting move-only iterators take two","October 2021","|Complete|","16.0","|format| |ranges|"
124124
`3568 <https://wg21.link/LWG3568>`__,"``basic_istream_view`` needs to initialize ``value_``","October 2021","|Complete|","16.0","|ranges|"
125-
`3570 <https://wg21.link/LWG3570>`__,"``basic_osyncstream::emit`` should be an unformatted output function","October 2021","",""
125+
`3570 <https://wg21.link/LWG3570>`__,"``basic_osyncstream::emit`` should be an unformatted output function","October 2021","|Complete|","18.0"
126126
`3571 <https://wg21.link/LWG3571>`__,"``flush_emit`` should set ``badbit`` if the ``emit`` call fails","October 2021","",""
127127
`3572 <https://wg21.link/LWG3572>`__,"``copyable-box`` should be fully ``constexpr``","October 2021","|Complete|","14.0","|ranges|"
128128
`3573 <https://wg21.link/LWG3573>`__,"Missing Throws element for ``basic_string_view(It begin, End end)``","October 2021","|Complete|","14.0"
@@ -275,7 +275,7 @@
275275
"`3857 <https://wg21.link/LWG3857>`__","``basic_string_view`` should allow explicit conversion when only traits vary","February 2023","|Complete|","17.0",""
276276
"`3860 <https://wg21.link/LWG3860>`__","``range_common_reference_t`` is missing","February 2023","|Complete|","17.0","|ranges|"
277277
"`3866 <https://wg21.link/LWG3866>`__","Bad Mandates for ``expected::transform_error`` overloads","February 2023","|Complete|","17.0",""
278-
"`3867 <https://wg21.link/LWG3867>`__","Should ``std::basic_osyncstream``'s move assignment operator be ``noexcept``?","February 2023","","",""
278+
"`3867 <https://wg21.link/LWG3867>`__","Should ``std::basic_osyncstream``'s move assignment operator be ``noexcept``?","February 2023","|Complete|","18.0",""
279279
"`3441 <https://wg21.link/LWG3441>`__","Misleading note about calls to customization points","February 2023","","",""
280280
"`3622 <https://wg21.link/LWG3622>`__","Misspecified transitivity of equivalence in §[unord.req.general]","February 2023","","",""
281281
"`3631 <https://wg21.link/LWG3631>`__","``basic_format_arg(T&&)`` should use ``remove_cvref_t<T>`` throughout","February 2023","|Complete|","17.0",""

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ set(files
10001000
string.h
10011001
string_view
10021002
strstream
1003+
syncstream
10031004
system_error
10041005
tgmath.h
10051006
thread

libcxx/include/__config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@
452452
# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
453453
# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
454454
# define _LIBCPP_HAS_NO_INCOMPLETE_TZDB
455+
# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
455456
# endif
456457

457458
// Need to detect which libc we're using if we're on Linux.

libcxx/include/__std_clang_module

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@
200200
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
201201
# include <strstream>
202202
#endif
203+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
204+
# include <syncstream>
205+
#endif
203206
#include <system_error>
204207
#include <tgmath.h>
205208
#if !defined(_LIBCPP_HAS_NO_THREADS)

libcxx/include/iosfwd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ using u8streampos = fpos<char_traits<char8_t>::state_type>; // C++20
9090
using u16streampos = fpos<char_traits<char16_t>::state_type>;
9191
using u32streampos = fpos<char_traits<char32_t>::state_type>;
9292
93+
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
94+
class basic_syncbuf; // C++20
95+
96+
using syncbuf = basic_syncbuf<char>; // C++20
97+
using wsyncbuf = basic_syncbuf<wchar_t>; // C++20
98+
99+
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
100+
class basic_osyncstream; // C++20
101+
102+
using osyncstream = basic_osyncstream<char>; // C++20
103+
using wosyncstream = basic_osyncstream<wchar_t>; // C++20
104+
93105
} // std
94106
95107
*/
@@ -130,6 +142,26 @@ typedef fpos<mbstate_t> u8streampos;
130142
typedef fpos<mbstate_t> u16streampos;
131143
typedef fpos<mbstate_t> u32streampos;
132144

145+
#if _LIBCPP_STD_VER >= 20
146+
147+
template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT>>
148+
class basic_syncbuf;
149+
150+
using syncbuf = basic_syncbuf<char>;
151+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
152+
using wsyncbuf = basic_syncbuf<wchar_t>;
153+
#endif
154+
155+
template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT>>
156+
class basic_osyncstream;
157+
158+
using osyncstream = basic_osyncstream<char>;
159+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
160+
using wosyncstream = basic_osyncstream<wchar_t>;
161+
#endif
162+
163+
#endif // _LIBCPP_STD_VER >=20
164+
133165
// Include other forward declarations here
134166
template <class _Tp, class _Alloc = allocator<_Tp> >
135167
class _LIBCPP_TEMPLATE_VIS vector;

libcxx/include/map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,8 @@ template <class _Key, class _Tp, class _Compare, class _Allocator>
17001700
_Tp&
17011701
map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
17021702
{
1703+
// TODO investigate this clang-tidy warning.
1704+
// NOLINTNEXTLINE(bugprone-use-after-move)
17031705
return __tree_.__emplace_unique_key_args(__k,
17041706
_VSTD::piecewise_construct,
17051707
_VSTD::forward_as_tuple(_VSTD::move(__k)),

libcxx/include/streambuf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ protected:
110110
#include <__assert> // all public C++ headers provide the assertion handler
111111
#include <__config>
112112
#include <__fwd/streambuf.h>
113+
#include <climits>
113114
#include <ios>
114115
#include <iosfwd>
115116
#include <version>

0 commit comments

Comments
 (0)