[libcxx-commits] [libcxx] [libc++][array] Test `[[nodicard]]` with `array::const_iterator` (PR #202070)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 6 11:51:07 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Hristo Hristov (H-G-Hristov)

<details>
<summary>Changes</summary>

Added tests with `array::const_iterator` for completeness.

Towards #<!-- -->172124

---
Full diff: https://github.com/llvm/llvm-project/pull/202070.diff


1 Files Affected:

- (modified) libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp (+14-1) 


``````````diff
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 a3ae77ae415f6..d2f4921a96ca2 100644
--- a/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/array/nodiscard.iterator.verify.cpp
@@ -17,23 +17,36 @@
 void test() {
   typedef std::array<int, 94> Container;
   Container c;
-  Container::iterator it = c.begin();
+  Container::iterator it        = c.begin();
+  Container::const_iterator cit = c.cbegin();
 
   // 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)}}}}
+  *cit;
 
   // 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)}}}}
+  cit[0];
 
   // 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)}}}}
+  cit + 1;
 
   // 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)}}}}
+  1 + cit;
 
   // 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)}}}}
+  cit - 1;
 
   // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   it - it;
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit - cit;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/202070


More information about the libcxx-commits mailing list