Skip to content

[libc++][array] Test [[nodicard]] with array::const_iterator#202070

Open
H-G-Hristov wants to merge 1 commit into
llvm:mainfrom
H-G-Hristov:hgh/libcxx/nodiscard-to-array
Open

[libc++][array] Test [[nodicard]] with array::const_iterator#202070
H-G-Hristov wants to merge 1 commit into
llvm:mainfrom
H-G-Hristov:hgh/libcxx/nodiscard-to-array

Conversation

@H-G-Hristov
Copy link
Copy Markdown
Contributor

Added tests with array::const_iterator for completeness.

Towards #172124

Added tests with `array::const_iterator` for completeness.
@H-G-Hristov H-G-Hristov requested a review from a team as a code owner June 6, 2026 18:50
@llvmorg-github-actions llvmorg-github-actions Bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 6, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-libcxx

Author: Hristo Hristov (H-G-Hristov)

Changes

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 --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@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   *it;
+  // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  *cit;
 
   // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   it[0];
+  // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit[0];
 
   // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   it + 1;
+  // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit + 1;
 
   // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   1 + it;
+  // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  1 + cit;
 
   // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   it - 1;
+  // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit - 1;
 
   // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
   it - it;
+  // expected-warning-re@+1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit - cit;
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants