[libcxx-commits] [libcxx] [libc++][span] Mark functions as `[[nodiscard]]` (PR #168033)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 17 02:03:58 PST 2025


================
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <array>
+#include <span>
+#include <vector>
+
+#include "test_macros.h"
+
+void test() {
+  { // Test with a static extent
+    std::array arr{94, 92};
+    std::span sp{arr};
----------------
philnik777 wrote:

In that case you can declare a function returning a span or pass the span as an argument.

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


More information about the libcxx-commits mailing list