[libcxx-commits] [libcxx] 3b5f8fe - [libc++][span] Test `[[nodiscard]]` applied to `span::iterator` (#202068)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 6 23:22:07 PDT 2026


Author: Hristo Hristov
Date: 2026-06-07T09:22:03+03:00
New Revision: 3b5f8fe2ac66b5bf7f447b1a29db8ac9c2d1820c

URL: https://github.com/llvm/llvm-project/commit/3b5f8fe2ac66b5bf7f447b1a29db8ac9c2d1820c
DIFF: https://github.com/llvm/llvm-project/commit/3b5f8fe2ac66b5bf7f447b1a29db8ac9c2d1820c.diff

LOG: [libc++][span] Test `[[nodiscard]]` applied to `span::iterator` (#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

Added: 
    libcxx/test/libcxx/containers/views/views.span/nodiscard.iterator.verify.cpp

Modified: 
    

Removed: 
    


################################################################################
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