[libcxx-commits] [libcxx] [libc++] Applied `[[nodiscard]]` to `array::iterator` (PR #198492)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 27 11:54:13 PDT 2026


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/198492

>From 58621e3ab850f974c26d7d801f2f40a6541a33eb Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 19 May 2026 13:52:53 +0300
Subject: [PATCH 1/8] [libc++] Applied `[[nodiscard]]` to
 `__static_bounded_iter`

Towards #172124
---
 .../include/__iterator/static_bounded_iter.h  | 15 +++---
 ...nodiscard.__static_bounded_iter.verify.cpp | 47 +++++++++++++++++++
 2 files changed, 55 insertions(+), 7 deletions(-)
 create mode 100644 libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp

diff --git a/libcxx/include/__iterator/static_bounded_iter.h b/libcxx/include/__iterator/static_bounded_iter.h
index d8fc7d185e7bc..9663820109670 100644
--- a/libcxx/include/__iterator/static_bounded_iter.h
+++ b/libcxx/include/__iterator/static_bounded_iter.h
@@ -128,7 +128,7 @@ struct __static_bounded_iter {
 
 public:
   // Dereference and indexing operations.
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT {
     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
         __current() != __end(), "__static_bounded_iter::operator*: Attempt to dereference an iterator at the end");
     return *__current();
@@ -140,7 +140,8 @@ struct __static_bounded_iter {
     return std::__to_address(__current());
   }
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference
+  operator[](difference_type __n) const _NOEXCEPT {
     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
         __n >= __begin() - __current(),
         "__static_bounded_iter::operator[]: Attempt to index an iterator past the start");
@@ -186,13 +187,13 @@ struct __static_bounded_iter {
     __current() += __n;
     return *this;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
   operator+(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT {
     __static_bounded_iter __tmp(__self);
     __tmp += __n;
     return __tmp;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
   operator+(difference_type __n, __static_bounded_iter const& __self) _NOEXCEPT {
     __static_bounded_iter __tmp(__self);
     __tmp += __n;
@@ -208,13 +209,13 @@ struct __static_bounded_iter {
     __current() -= __n;
     return *this;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
   operator-(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT {
     __static_bounded_iter __tmp(__self);
     __tmp -= __n;
     return __tmp;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type
   operator-(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
     return __x.__current() - __y.__current();
   }
@@ -306,7 +307,7 @@ struct pointer_traits<__static_bounded_iter<_Iterator, _Size> > {
   using element_type    = typename pointer_traits<_Iterator>::element_type;
   using difference_type = typename pointer_traits<_Iterator>::difference_type;
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __it) _NOEXCEPT {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __it) _NOEXCEPT {
     return std::__to_address(__it.__current());
   }
 };
diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp
new file mode 100644
index 0000000000000..95e43cb7b9b86
--- /dev/null
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY
+
+// <array>
+
+// Check that functions are marked [[nodiscard]]
+
+#include <array>
+
+#include "test_macros.h"
+
+void test() { // __static_bounded_iter
+  typedef std::array<int, 94> Container;
+  ASSERT_SAME_TYPE(Container::iterator, std::__static_bounded_iter<int*, 94>);
+
+  Container::iterator it;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *it;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it[0];
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it + 1;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  1 + it;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - 1;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - it;
+
+  std::pointer_traits<Container::iterator> pt;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  pt.to_address(it);
+}

>From 7b7867a3f4e813170322b1c5fb59477ae01e674a Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 21 May 2026 09:14:10 +0300
Subject: [PATCH 2/8] Comments - attempt 2

---
 ...rify.cpp => nodiscard.iterator.verify.cpp} | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
 rename libcxx/test/libcxx/containers/sequences/array/{nodiscard.__static_bounded_iter.verify.cpp => nodiscard.iterator.verify.cpp} (74%)

diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
similarity index 74%
rename from libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp
rename to libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
index 95e43cb7b9b86..390d34a66862d 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.__static_bounded_iter.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
 
 // <array>
 
@@ -16,11 +17,18 @@
 
 #include "test_macros.h"
 
-void test() { // __static_bounded_iter
+void test() {
   typedef std::array<int, 94> Container;
-  ASSERT_SAME_TYPE(Container::iterator, std::__static_bounded_iter<int*, 94>);
+  Container c;
+  Container::iterator it = c.begin();
 
-  Container::iterator it;
+#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
+  ASSERT_SAME_TYPE(Container::iterator, std::__static_bounded_iter<int*, 94>);
+#elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
+  ASSERT_SAME_TYPE(Container::iterator, std::__wrap_iter<int*>);
+#else
+  ASSERT_SAME_TYPE(Container::iterator, int*);
+#endif
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   *it;
@@ -40,8 +48,8 @@ void test() { // __static_bounded_iter
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   it - it;
 
-  std::pointer_traits<Container::iterator> pt;
-
+#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  pt.to_address(it);
+  std::pointer_traits<Container::iterator>::to_address(it);
+#endif
 }

>From ac6f362e608f6015171083395647267309d362a9 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 21 May 2026 09:14:35 +0300
Subject: [PATCH 3/8] Cleanup

---
 .../containers/sequences/array/nodiscard.iterator.verify.cpp   | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
index 390d34a66862d..eb691891c7f49 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
-
 // <array>
 
 // Check that functions are marked [[nodiscard]]

>From 6b6d9b4456b2928d23e37a5bf5c17106b952c8e6 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 22 May 2026 10:17:59 +0300
Subject: [PATCH 4/8] `[[nodiscard]]` to `__wrap_iter`

---
 libcxx/include/__iterator/wrap_iter.h | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 0633794e15080..b823a636d38d5 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -55,7 +55,9 @@ class __wrap_iter {
                 int> = 0>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_OtherIter>& __u) _NOEXCEPT
       : __i_(__u.__i_) {}
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { return *__i_; }
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT {
+    return *__i_;
+  }
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT {
     return std::__to_address(__i_);
   }
@@ -78,7 +80,8 @@ class __wrap_iter {
     --(*this);
     return __tmp;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator+(difference_type __n) const _NOEXCEPT {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
+  operator+(difference_type __n) const _NOEXCEPT {
     __wrap_iter __w(*this);
     __w += __n;
     return __w;
@@ -87,14 +90,16 @@ class __wrap_iter {
     __i_ += __n;
     return *this;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator-(difference_type __n) const _NOEXCEPT {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
+  operator-(difference_type __n) const _NOEXCEPT {
     return *this + (-__n);
   }
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter& operator-=(difference_type __n) _NOEXCEPT {
     *this += -__n;
     return *this;
   }
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference
+  operator[](difference_type __n) const _NOEXCEPT {
     return __i_[__n];
   }
 
@@ -201,18 +206,18 @@ class __wrap_iter {
 
 #ifndef _LIBCPP_CXX03_LANG
   template <class _Iter2>
-  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 auto
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 auto
   operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.__i_ - __y.__i_)
 #else
   template <class _Iter2>
-  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14
   typename __wrap_iter::difference_type operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 #endif // C++03
   {
     return __x.__i_ - __y.__i_;
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
   operator+(typename __wrap_iter::difference_type __n, __wrap_iter __x) _NOEXCEPT {
     __x += __n;
     return __x;

>From 92adfe89d60cff63146ceffd4ec51a1af2bdbb1c Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 22 May 2026 10:40:06 +0300
Subject: [PATCH 5/8] Add "expression result  unused"

---
 .../array/nodiscard.iterator.verify.cpp       | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
index eb691891c7f49..8697b744de248 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -27,6 +27,7 @@ void test() {
   ASSERT_SAME_TYPE(Container::iterator, int*);
 #endif
 
+#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) || defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   *it;
 
@@ -44,6 +45,25 @@ void test() {
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   it - it;
+#else
+  // expected-warning at +1 {{expression result unused}}
+  *it;
+
+  // expected-warning at +1 {{expression result unused}}
+  it[0];
+
+  // expected-warning at +1 {{expression result unused}}
+  it + 1;
+
+  // expected-warning at +1 {{expression result unused}}
+  1 + it;
+
+  // expected-warning at +1 {{expression result unused}}
+  it - 1;
+
+  // expected-warning at +1 {{expression result unused}}
+  it - it;
+#endif
 
 #if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}

>From 7f0bf566c5fd959bbc5ab48b4411d3ec6f9c8575 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 22 May 2026 10:47:42 +0300
Subject: [PATCH 6/8] Haderning only

---
 .../array/nodiscard.iterator.verify.cpp       | 24 ++-----------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
index 8697b744de248..c2409a92020cc 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: libcpp-hardening-mode=none
+
 // <array>
 
 // Check that functions are marked [[nodiscard]]
@@ -23,11 +25,8 @@ void test() {
   ASSERT_SAME_TYPE(Container::iterator, std::__static_bounded_iter<int*, 94>);
 #elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
   ASSERT_SAME_TYPE(Container::iterator, std::__wrap_iter<int*>);
-#else
-  ASSERT_SAME_TYPE(Container::iterator, int*);
 #endif
 
-#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) || defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   *it;
 
@@ -45,25 +44,6 @@ void test() {
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   it - it;
-#else
-  // expected-warning at +1 {{expression result unused}}
-  *it;
-
-  // expected-warning at +1 {{expression result unused}}
-  it[0];
-
-  // expected-warning at +1 {{expression result unused}}
-  it + 1;
-
-  // expected-warning at +1 {{expression result unused}}
-  1 + it;
-
-  // expected-warning at +1 {{expression result unused}}
-  it - 1;
-
-  // expected-warning at +1 {{expression result unused}}
-  it - it;
-#endif
 
 #if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}

>From 111a8e6617db656fadd9e843d6e5ca0cb8ad7b8f Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 22 May 2026 12:09:28 +0300
Subject: [PATCH 7/8] Try again

---
 .../array/nodiscard.iterator.verify.cpp       | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
index c2409a92020cc..8697b744de248 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: libcpp-hardening-mode=none
-
 // <array>
 
 // Check that functions are marked [[nodiscard]]
@@ -25,8 +23,11 @@ void test() {
   ASSERT_SAME_TYPE(Container::iterator, std::__static_bounded_iter<int*, 94>);
 #elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
   ASSERT_SAME_TYPE(Container::iterator, std::__wrap_iter<int*>);
+#else
+  ASSERT_SAME_TYPE(Container::iterator, int*);
 #endif
 
+#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) || defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   *it;
 
@@ -44,6 +45,25 @@ void test() {
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   it - it;
+#else
+  // expected-warning at +1 {{expression result unused}}
+  *it;
+
+  // expected-warning at +1 {{expression result unused}}
+  it[0];
+
+  // expected-warning at +1 {{expression result unused}}
+  it + 1;
+
+  // expected-warning at +1 {{expression result unused}}
+  1 + it;
+
+  // expected-warning at +1 {{expression result unused}}
+  it - 1;
+
+  // expected-warning at +1 {{expression result unused}}
+  it - it;
+#endif
 
 #if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}

>From bad967357b31480181b6507fd67ab58e675f8c8a Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 27 May 2026 21:47:01 +0300
Subject: [PATCH 8/8] Review comments

---
 .../array/nodiscard.iterator.verify.cpp       | 40 +++----------------
 1 file changed, 6 insertions(+), 34 deletions(-)

diff --git a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
index 8697b744de248..91b18319b37b9 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -19,51 +19,23 @@ void test() {
   Container c;
   Container::iterator it = c.begin();
 
-#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
-  ASSERT_SAME_TYPE(Container::iterator, std::__static_bounded_iter<int*, 94>);
-#elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
-  ASSERT_SAME_TYPE(Container::iterator, std::__wrap_iter<int*>);
-#else
-  ASSERT_SAME_TYPE(Container::iterator, int*);
-#endif
-
-#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) || defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
   *it;
 
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
   it[0];
 
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
   it + 1;
 
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
   1 + it;
 
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
   it - 1;
 
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
   it - it;
-#else
-  // expected-warning at +1 {{expression result unused}}
-  *it;
-
-  // expected-warning at +1 {{expression result unused}}
-  it[0];
-
-  // expected-warning at +1 {{expression result unused}}
-  it + 1;
-
-  // expected-warning at +1 {{expression result unused}}
-  1 + it;
-
-  // expected-warning at +1 {{expression result unused}}
-  it - 1;
-
-  // expected-warning at +1 {{expression result unused}}
-  it - it;
-#endif
 
 #if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}



More information about the libcxx-commits mailing list