[libcxx-commits] [libcxx] [libc++] Revert undesired `[[nodiscard]]` added to conversion functions (PR #173658)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Dec 26 04:53:05 PST 2025
https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/173658
Because
- no one should use them in explicit function call forms, and
- value-discarding casts to non-`void` are already diagnosed.
>From db9f2b45220939dc455dec879f455903ac10ea9f Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Fri, 26 Dec 2025 19:45:18 +0800
Subject: [PATCH] [libc++] Revert undesired `[[nodiscard]]` added to conversion
functions
Because
- no one should use them in explicit function call forms, and
- value-discarding casts to non-`void` are already diagnosed.
---
libcxx/include/__ios/fpos.h | 2 +-
libcxx/include/ios | 4 ++--
.../input.output/iostreams.base/nodiscard.verify.cpp | 7 -------
3 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/libcxx/include/__ios/fpos.h b/libcxx/include/__ios/fpos.h
index 655158c6f2d89..af114421c839f 100644
--- a/libcxx/include/__ios/fpos.h
+++ b/libcxx/include/__ios/fpos.h
@@ -28,7 +28,7 @@ class fpos {
public:
_LIBCPP_HIDE_FROM_ABI fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI operator streamoff() const { return __off_; }
+ _LIBCPP_HIDE_FROM_ABI operator streamoff() const { return __off_; }
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _StateT state() const { return __st_; }
_LIBCPP_HIDE_FROM_ABI void state(_StateT __st) { __st_ = __st; }
diff --git a/libcxx/include/ios b/libcxx/include/ios
index 1055af0dc9130..9cf0aa8998ed1 100644
--- a/libcxx/include/ios
+++ b/libcxx/include/ios
@@ -575,9 +575,9 @@ public:
# ifdef _LIBCPP_CXX03_LANG
// Preserve the ability to compare with literal 0,
// and implicitly convert to bool, but not implicitly convert to int.
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI operator void*() const { return fail() ? nullptr : (void*)this; }
+ _LIBCPP_HIDE_FROM_ABI operator void*() const { return fail() ? nullptr : (void*)this; }
# else
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return !fail(); }
+ _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return !fail(); }
# endif
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool operator!() const { return fail(); }
diff --git a/libcxx/test/libcxx/input.output/iostreams.base/nodiscard.verify.cpp b/libcxx/test/libcxx/input.output/iostreams.base/nodiscard.verify.cpp
index 84386fe3a725e..5806babebcfcd 100644
--- a/libcxx/test/libcxx/input.output/iostreams.base/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/input.output/iostreams.base/nodiscard.verify.cpp
@@ -46,11 +46,6 @@ void test() {
{
std::ios& ref = stream;
-#if TEST_STD_VER >= 11
- ref.operator bool(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#else
- ref.operator void*(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#endif
!ref; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
ref.rdstate(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
ref.good(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -70,8 +65,6 @@ void test() {
{
std::fpos<std::mbstate_t> pos;
- // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- pos.operator std::streamoff();
pos.state(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
pos + std::streamoff(0);
More information about the libcxx-commits
mailing list