[libcxx-commits] [libcxx] [libc++][string_view] Test [[nodiscard]] applied to `string_view::const_iterator` (PR #202203)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 7 06:23:22 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/202203.diff


1 Files Affected:

- (added) libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp (+41) 


``````````diff
diff --git a/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp
new file mode 100644
index 0000000000000..f7ec54bc7a9f7
--- /dev/null
+++ b/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_view>
+
+// Check that functions are marked [[nodiscard]]
+
+#include <string_view>
+
+#include "test_macros.h"
+
+void test() {
+  typedef std::string_view Container;
+  Container c;
+  Container::const_iterator cit = c.begin();
+
+  // 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)}}}}
+  cit[0];
+
+  // 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 + 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)}}}}
+  cit - cit;
+}

``````````

</details>


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


More information about the libcxx-commits mailing list