[libcxx-commits] [libcxx] ccd06e4 - [libc++][istream] P3223R2: Making `std::istream::ignore` less surprising (#147007)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 30 08:26:34 PDT 2025
Author: Hristo Hristov
Date: 2025-09-30T11:26:30-04:00
New Revision: ccd06e48098b826cafcc2e553a8cb9081e0a06dc
URL: https://github.com/llvm/llvm-project/commit/ccd06e48098b826cafcc2e553a8cb9081e0a06dc
DIFF: https://github.com/llvm/llvm-project/commit/ccd06e48098b826cafcc2e553a8cb9081e0a06dc.diff
LOG: [libc++][istream] P3223R2: Making `std::istream::ignore` less surprising (#147007)
Implements https://wg21.link/P3223R2 as a DR as, as recommended in
https://github.com/cplusplus/papers/issues/1871#issuecomment-2993018698.
Resolves -1L ambiguity.
Closes #148178
Added:
libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.char_type.pass.cpp
Modified:
libcxx/docs/ReleaseNotes/22.rst
libcxx/docs/Status/Cxx2cPapers.csv
libcxx/include/istream
Removed:
################################################################################
diff --git a/libcxx/docs/ReleaseNotes/22.rst b/libcxx/docs/ReleaseNotes/22.rst
index 87d86c1345618..8d023a14e89e6 100644
--- a/libcxx/docs/ReleaseNotes/22.rst
+++ b/libcxx/docs/ReleaseNotes/22.rst
@@ -41,6 +41,7 @@ Implemented Papers
- P2321R2: ``zip`` (`Github <https://llvm.org/PR105169>`__) (The paper is partially implemented. ``zip_transform_view``
is implemented in this release)
- P3044R2: sub-``string_view`` from ``string`` (`Github <https://llvm.org/PR148140>`__)
+- P3223R2: Making ``std::istream::ignore`` less surprising (`Github <https://llvm.org/PR148178>`__)
- P3168R2: Give ``std::optional`` Range Support (`Github <https://llvm.org/PR105430>`__)
Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 9e1678f22c4be..4e0918b0246c1 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -151,7 +151,7 @@
"`P3111R8 <https://wg21.link/P3111R8>`__","Atomic Reduction Operations","2025-06 (Sofia)","","","`#148174 <https://github.com/llvm/llvm-project/issues/148174>`__",""
"`P3060R3 <https://wg21.link/P3060R3>`__","Add ``std::views::indices(n)``","2025-06 (Sofia)","","","`#148175 <https://github.com/llvm/llvm-project/issues/148175>`__",""
"`P2319R5 <https://wg21.link/P2319R5>`__","Prevent ``path`` presentation problems","2025-06 (Sofia)","","","`#148177 <https://github.com/llvm/llvm-project/issues/148177>`__",""
-"`P3223R2 <https://wg21.link/P3223R2>`__","Making ``std::istream::ignore`` less surprising","2025-06 (Sofia)","","","`#148178 <https://github.com/llvm/llvm-project/issues/148178>`__",""
+"`P3223R2 <https://wg21.link/P3223R2>`__","Making ``std::istream::ignore`` less surprising","2025-06 (Sofia)","|Complete|","22","`#148178 <https://github.com/llvm/llvm-project/issues/148178>`__",""
"`P2781R9 <https://wg21.link/P2781R9>`__","``std::constant_wrapper``","2025-06 (Sofia)","","","`#148179 <https://github.com/llvm/llvm-project/issues/148179>`__",""
"`P3697R1 <https://wg21.link/P3697R1>`__","Minor additions to C++26 standard library hardening","2025-06 (Sofia)","","","`#148180 <https://github.com/llvm/llvm-project/issues/148180>`__",""
"`P3552R3 <https://wg21.link/P3552R3>`__","Add a Coroutine Task Type","2025-06 (Sofia)","","","`#148182 <https://github.com/llvm/llvm-project/issues/148182>`__",""
diff --git a/libcxx/include/istream b/libcxx/include/istream
index 93def61a8b477..7f15521f91a8a 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -70,6 +70,7 @@ public:
basic_istream& getline(char_type* s, streamsize n, char_type delim);
basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
+ basic_istream& ignore(streamsize n, char_type delim); // Since C++26, implemented as a DR
int_type peek();
basic_istream& read (char_type* s, streamsize n);
streamsize readsome(char_type* s, streamsize n);
@@ -172,6 +173,7 @@ template <class Stream, class T>
# include <__type_traits/conjunction.h>
# include <__type_traits/enable_if.h>
# include <__type_traits/is_base_of.h>
+# include <__type_traits/is_same.h>
# include <__type_traits/make_unsigned.h>
# include <__utility/declval.h>
# include <__utility/forward.h>
@@ -292,6 +294,10 @@ public:
basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
+ template <class _Tp = char_type, __enable_if_t<is_same<_Tp, char>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI basic_istream& ignore(streamsize __n, char_type __delim) {
+ return ignore(__n, traits_type::to_int_type(__delim));
+ }
int_type peek();
basic_istream& read(char_type* __s, streamsize __n);
streamsize readsome(char_type* __s, streamsize __n);
diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.char_type.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.char_type.pass.cpp
new file mode 100644
index 0000000000000..d0d174c1d4d87
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.char_type.pass.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Requires 396145d in the built library.
+// XFAIL: using-built-library-before-llvm-9
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
+// <istream>
+
+// basic_istream& ignore(streamsize n, char_type delim);
+
+#include <cassert>
+#include <sstream>
+#include <string>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ std::istringstream in("\xF0\x9F\xA4\xA1 Clown Face");
+ in.ignore(100, '\xA1'); // Ignore up to '\xA1' delimiter,
+ // previously might have ignored to EOF.
+
+ assert(in.gcount() == 4); // 4 bytes were ignored.
+ assert(in.peek() == ' '); // Next character is a space.
+
+ std::string str; // Read the next word.
+ in >> str;
+ assert(str == "Clown");
+
+ // Parameter value "-1L" doesn't cause ambiguity with the char_type overload.
+ in.ignore(100, -1L); // Ignore up to EOF, which is the default behavior.
+ assert(in.eof()); // Stream should be at EOF now.
+ assert(in.gcount() == 5);
+
+ return 0;
+}
More information about the libcxx-commits
mailing list