[libcxx-commits] [libcxx] [libc++][string] [libc++][span] Test [[nodiscard]] applied to `basic_string::iterator` (PR #202202)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jun 7 06:18:45 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>
Adds test coverage.
`[[nodicard]]` applied in:
- https://github.com/llvm/llvm-project/pull/198489
- https://github.com/llvm/llvm-project/pull/198492
Towards #<!-- -->172124
---
Full diff: https://github.com/llvm/llvm-project/pull/202202.diff
1 Files Affected:
- (added) libcxx/test/libcxx/strings/basic.string/nodiscard.iterator.verify.cpp (+52)
``````````diff
diff --git a/libcxx/test/libcxx/strings/basic.string/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/strings/basic.string/nodiscard.iterator.verify.cpp
new file mode 100644
index 0000000000000..7fd6872158757
--- /dev/null
+++ b/libcxx/test/libcxx/strings/basic.string/nodiscard.iterator.verify.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// Check that functions are marked [[nodiscard]]
+
+#include <string>
+
+#include "test_macros.h"
+
+void test() {
+ typedef std::string Container;
+ Container c;
+ 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/202202
More information about the libcxx-commits
mailing list