[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:39:48 PDT 2026


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

>From 35d85e54c81a7a0453dffdaca6d3d067b895a0ea 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 | 39 +++++++++++++++++++
 1 file changed, 39 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..b8eb5f835b597
--- /dev/null
+++ b/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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)}}}}
+  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