[libcxx-commits] [libcxx] [libc++][array] Applied `[[nodiscard]]` (PR #168829)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 20 04:09:22 PST 2025


================
@@ -11,13 +11,96 @@
 // check that <array> functions are marked [[nodiscard]]
 
 #include <array>
+#include <utility>
+
+#include <test_macros.h>
 
 void array_test() {
-  std::array<int, 1> array;
-  array.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::array<int, 1> a;
+  const std::array<int, 1> ca{9482};
+
+  a.begin();    // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
----------------
philnik777 wrote:

We could put this into a template and make these all `expected-warning 2`. That'd remove a bunch of lines here and make sure we're not forgetting any annotations on only one of the specializations. It'd also make clear which functions can't be called on the zero-size array.

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


More information about the libcxx-commits mailing list