[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 22:19:57 PDT 2026
https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/198492
>From 6e3603f9136fe5592cc2f0ff2044841f2e601c89 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/9] [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 d3840fe5e97eee636274a01d32b9ce3dc3fef311 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/9] 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 3a7cc977a0240e3c621a7696f10e8b0113b83ed0 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/9] 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 0b0c99002368e76243a8ffdbed0816cad594ebb9 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/9] `[[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 72f8b94962f983a3d3fcbaa151bb2336f285e4ae 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/9] 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 291c4fa75c087aa7c83a99948da6c728e650fa65 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/9] 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 77b32debae31fdc346286a8ee5f3ba754fcaf143 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/9] 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 9856f9924ce45bf25b6f636bdfddff6f8de5820c 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/9] 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}}
>From 16bd4af237eb33f4f2af1f6cff8a3d9a390bdd11 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 27 May 2026 22:14:19 +0300
Subject: [PATCH 9/9] Correct syntax
---
.../sequences/array/nodiscard.iterator.verify.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 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 91b18319b37b9..4a4bf31e019c0 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -19,22 +19,22 @@ void test() {
Container c;
Container::iterator it = c.begin();
- // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
+ // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
*it;
- // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
+ // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
it[0];
- // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
+ // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
it + 1;
- // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
+ // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
1 + it;
- // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
+ // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
it - 1;
- // expected-warning-re at +1 {{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}
+ // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
it - it;
#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
More information about the libcxx-commits
mailing list