[libcxx-commits] [libcxx] [libc++] Fix constexpr initialization of std::array<T, 0> (PR #74667)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 14 07:59:19 PST 2023


================
@@ -0,0 +1,142 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <array>
+
+// template <class T, size_t N>
+// struct array
+
+// Make sure std::array<T, N> has the correct object size and alignment.
+// This test is mostly meant to catch subtle ABI-breaking regressions.
+
+// Ignore error about requesting a large alignment not being ABI compatible with older AIX systems.
+#if defined(_AIX)
+#  pragma clang diagnostic ignored "-Waix-compat"
+#endif
+
+#include <array>
+#include <cstddef>
+#include <type_traits>
+
+#include "test_macros.h"
+
+template <class T, std::size_t Size>
+struct MyArray {
+  T elems[Size];
+};
+
+template <class T>
+void test_type() {
+  {
+    using Array = std::array<T, 0>;
+    static_assert(sizeof(Array) == sizeof(T), "");
+    static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
+    static_assert(sizeof(Array) == sizeof(T[1]), "");
+    static_assert(sizeof(Array) == sizeof(MyArray<T, 1>), "");
+    static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 1>), "");
+    static_assert(!std::is_empty<Array>::value, "");
----------------
philnik777 wrote:

I was only talking about the zero-sized ones. The reality is that implementations already disagree on most things tested here: https://godbolt.org/z/75hqP4Yx6

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


More information about the libcxx-commits mailing list