diff --git a/libcxx/docs/ReleaseNotes/21.rst b/libcxx/docs/ReleaseNotes/21.rst index 3d70fa38d971e..3dc918d37397d 100644 --- a/libcxx/docs/ReleaseNotes/21.rst +++ b/libcxx/docs/ReleaseNotes/21.rst @@ -51,6 +51,7 @@ Implemented Papers - P2441R2: ``views::join_with`` (`Github `__) - P2711R1: Making multi-param constructors of ``views`` ``explicit`` (`Github `__) - P2770R0: Stashing stashing ``iterators`` for proper flattening (`Github `__) +- P3223R2: Making ``std::istream::ignore`` less surprising - P2655R3: ``common_reference_t`` of ``reference_wrapper`` Should Be a Reference Type (`Github `__) Improvements and New Features diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv index a1854a6acc41a..3dd2a56b3f83c 100644 --- a/libcxx/docs/Status/Cxx2cPapers.csv +++ b/libcxx/docs/Status/Cxx2cPapers.csv @@ -149,7 +149,7 @@ "`P3008R6 `__","Atomic floating-point min/max","2025-06 (Sofia)","","","" "`P3111R8 `__","Atomic Reduction Operations","2025-06 (Sofia)","","","" "`P3060R3 `__","Add ``std::views::indices(n)``","2025-06 (Sofia)","","","" -"`P2319R5 `__","Prevent ``path`` presentation problems","2025-06 (Sofia)","","","" +"`P2319R5 `__","Prevent ``path`` presentation problems","2025-06 (Sofia)","|Complete|","21","" "`P3223R2 `__","Making ``std::istream::ignore`` less surprising","2025-06 (Sofia)","","","" "`P2781R9 `__","``std::constant_wrapper``","2025-06 (Sofia)","","","" "`P3697R1 `__","Minor additions to C++26 standard library hardening","2025-06 (Sofia)","","","" diff --git a/libcxx/include/istream b/libcxx/include/istream index 93def61a8b477..fb5d35c2644d1 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); @@ -172,6 +173,7 @@ template # 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,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 + { + 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 + +// + +// basic_istream& ignore(streamsize n, char_type delim); + +#include +#include +#include + +#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 + +// + +// basic_istream& ignore(streamsize n, char_type delim); + +#include +#include +#include + +#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}} +}