[libcxx-commits] [libcxx] [libc++][span] Test `[[nodiscard]]` applied to `span::iterator` (PR #202068)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 6 11:40:39 PDT 2026
https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/202068
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 8ab8153707c23b1e9228b183e42e710d4823acfe Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 6 Jun 2026 21:39:48 +0300
Subject: [PATCH] [libc++][span] Test `[[nodiscard]]` applied to
`span::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
---
.../views.span/nodiscard.iterator.verify.cpp | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 libcxx/test/libcxx/containers/views/views.span/nodiscard.iterator.verify.cpp
diff --git a/libcxx/test/libcxx/containers/views/views.span/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/views/views.span/nodiscard.iterator.verify.cpp
new file mode 100644
index 0000000000000..f7ead979c8737
--- /dev/null
+++ b/libcxx/test/libcxx/containers/views/views.span/nodiscard.iterator.verify.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++20
+
+// <span>
+
+// Check that functions are marked [[nodiscard]]
+
+#include <span>
+
+#include "test_macros.h"
+
+void test() {
+ using Container = std::span<int, 82>;
+
+ int arr[82] = {};
+ Container c{arr};
+ Container::iterator it = c.begin();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ *it;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it[0];
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it + 1;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ 1 + it;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it - 1;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it - it;
+}
More information about the libcxx-commits
mailing list