[libc] [compiler-rt] [libcxxabi] [lldb] [llvm] [clang] [flang] [clang-tools-extra] [libunwind] [libcxx] [libc++][span] P2447R4: `std::span` over an initializer list (PR #78157)

Mark de Wever via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 18 08:46:22 PST 2024


================
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// REQUIRES: has-unix-headers
+// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
+// XFAIL: availability-verbose_abort-missing
+
+// <span>
+
+// constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); // Since C++26
+
+#include <cassert>
+#include <initializer_list>
+#include <span>
+
+#include "check_assertion.h"
+
+bool test() {
+  TEST_LIBCPP_ASSERT_FAILURE(
+      (std::span<const int, 4>({1, 2, 3, 9084, 5})), "Size mismatch in span's constructor _Extent != __il.size().");
+  TEST_LIBCPP_ASSERT_FAILURE((std::span<const int, 4>(std::initializer_list<int>{1, 2, 3, 9084, 5})),
+                             "Size mismatch in span's constructor _Extent != __il.size().");
+
+  return true;
+}
+
+int main(int, char**) {
+  assert(test());
----------------
mordante wrote:

We typically don't do this for run-time tests. We do it for compile-time tests so we can use `static_assert`s. In this case I would remove the `test` function and move the test code in `main`.

I overlooked this in the previous review.

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


More information about the cfe-commits mailing list