[libcxx-commits] [libcxx] e4b8d8a - [libc++][istream] Removed `[[nodiscard]]` from `peek()` (#175591)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 12 19:55:07 PST 2026
Author: Hristo Hristov
Date: 2026-01-13T05:55:03+02:00
New Revision: e4b8d8a474c493f02baff5e11fb9a74d70c02a54
URL: https://github.com/llvm/llvm-project/commit/e4b8d8a474c493f02baff5e11fb9a74d70c02a54
DIFF: https://github.com/llvm/llvm-project/commit/e4b8d8a474c493f02baff5e11fb9a74d70c02a54.diff
LOG: [libc++][istream] Removed `[[nodiscard]]` from `peek()` (#175591)
Calling `peek()` after constructing a stream is something one can use to
make the stream ignore empty inputs:
```
#include <sstream>
int main() {
std::istringstream s;
s.peek();
while (s && !s.eof()) {
char c;
s >> c;
printf("not eof; read \'%c\' (%d)\n", c, c);
}
}
```
as discussed in
https://github.com/llvm/llvm-project/pull/173754#discussion_r2669631585
this patch removes the `[[nodiscard]]` annotation.
Added:
Modified:
libcxx/include/istream
libcxx/test/libcxx/input.output/iostream.format/nodiscard.verify.cpp
Removed:
################################################################################
diff --git a/libcxx/include/istream b/libcxx/include/istream
index 5f805e8a37d13..dfa22e9f3bfb7 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -298,7 +298,7 @@ public:
_LIBCPP_HIDE_FROM_ABI basic_istream& ignore(streamsize __n, char_type __delim) {
return ignore(__n, traits_type::to_int_type(__delim));
}
- [[__nodiscard__]] int_type peek();
+ int_type peek();
basic_istream& read(char_type* __s, streamsize __n);
streamsize readsome(char_type* __s, streamsize __n);
diff --git a/libcxx/test/libcxx/input.output/iostream.format/nodiscard.verify.cpp b/libcxx/test/libcxx/input.output/iostream.format/nodiscard.verify.cpp
index 959e99fb89098..aa7df6a67e356 100644
--- a/libcxx/test/libcxx/input.output/iostream.format/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/input.output/iostream.format/nodiscard.verify.cpp
@@ -28,9 +28,6 @@ void test() {
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
stream.gcount();
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- stream.peek();
-
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
stream.tellg();
}
More information about the libcxx-commits
mailing list