-
Notifications
You must be signed in to change notification settings - Fork 14.4k
WIP [libc++][istream] P3223R2: Making std::istream::ignore
less surprising
#147007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
H-G-Hristov
wants to merge
5
commits into
llvm:main
Choose a base branch
from
H-G-Hristov:hgh/libcxx/P3223R2-Making-std_istream_ignore-less-surprising
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP [libc++][istream] P3223R2: Making std::istream::ignore
less surprising
#147007
H-G-Hristov
wants to merge
5
commits into
llvm:main
from
H-G-Hristov:hgh/libcxx/P3223R2-Making-std_istream_ignore-less-surprising
+74
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements [P3223R2](https://wg21.link/P3223R2) # References - cplusplus/draft#7996
@llvm/pr-subscribers-libcxx Author: Hristo Hristov (H-G-Hristov) ChangesImplements P3223R2 ReferencesFull diff: https://github.com/llvm/llvm-project/pull/147007.diff 4 Files Affected:
diff --git a/libcxx/docs/ReleaseNotes/21.rst b/libcxx/docs/ReleaseNotes/21.rst
index 08b32bb508dc1..34735ca515d53 100644
--- a/libcxx/docs/ReleaseNotes/21.rst
+++ b/libcxx/docs/ReleaseNotes/21.rst
@@ -51,6 +51,7 @@ Implemented Papers
- P2441R2: ``views::join_with`` (`Github <https://github.com/llvm/llvm-project/issues/105185>`__)
- P2711R1: Making multi-param constructors of ``views`` ``explicit`` (`Github <https://github.com/llvm/llvm-project/issues/105252>`__)
- P2770R0: Stashing stashing ``iterators`` for proper flattening (`Github <https://github.com/llvm/llvm-project/issues/105250>`__)
+- P3223R2: Making ``std::istream::ignore`` less surprising
Improvements and New Features
-----------------------------
diff --git a/libcxx/include/istream b/libcxx/include/istream
index 02546902494e3..83ba1799cae91 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
int_type peek();
basic_istream& read (char_type* s, streamsize n);
streamsize readsome(char_type* s, streamsize n);
@@ -171,6 +172,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>
@@ -291,6 +293,13 @@ public:
basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
+# if _LIBCPP_STD_VER >= 26
+ _LIBCPP_HIDE_FROM_ABI basic_istream& ignore(streamsize __n, char_type __delim)
+ requires is_same_v<char_type, char>
+ {
+ return this->ignore(__n, _Traits::to_int_type(__delim));
+ }
+# endif
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..9d83a7ea15027
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.char_type.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: std-at-least-c++26
+
+// Requires 396145d in the built library.
+// XFAIL: using-built-library-before-llvm-9
+
+// <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");
+
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.verify.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.verify.cpp
new file mode 100644
index 0000000000000..54d13cac69b94
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.verify.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: std-at-least-c++26
+
+// Requires 396145d in the built library.
+// XFAIL: using-built-library-before-llvm-9
+
+// <istream>
+
+// basic_istream& ignore(streamsize n, char_type delim);
+
+#include <cassert>
+#include <sstream>
+#include <string>
+
+#include "test_macros.h"
+
+void test() {
+ std::istringstream in("\xF0\x9F\xA4\xA1 Clown Face");
+ in.ignore(100, -1L); // expected-error {{call to member function 'ignore' is ambiguous}}
+}
|
Zingam
reviewed
Jul 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements P3223R2
References