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

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 7 06:22:48 PDT 2026


https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/202203

Adds test coverage.

`[[nodicard]]` applied in:
- https://github.com/llvm/llvm-project/pull/198489
- https://github.com/llvm/llvm-project/pull/198492

Towards #172124

>From 716482fb79a674d41db69eb94fd7f10e3f4ad7c9 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 7 Jun 2026 16:22:28 +0300
Subject: [PATCH] [libc++][string_view] Test [[nodiscard]] applied to
 `string_view::const_iterator`

Adds test coverage.

`[[nodicard]]` applied in:
- https://github.com/llvm/llvm-project/pull/198489
- https://github.com/llvm/llvm-project/pull/198492

Towards #172124
---
 .../string.view/nodiscard.iterator.verify.cpp | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp

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;
+}



More information about the libcxx-commits mailing list