[libcxx-commits] [libcxx] [libc++] Fix constexpr initialization of std::array<T, 0> (PR #74667)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Dec 9 04:19:45 PST 2023
================
@@ -0,0 +1,130 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "test_macros.h"
+
+template <class T, std::size_t Size>
+struct MyArray {
+ T elems[Size];
+};
+
+template <class T>
+void test_type() {
+ {
+ static_assert(sizeof(std::array<T, 0>) == sizeof(T), "");
+ static_assert(alignof(std::array<T, 0>) == alignof(T), "");
+ static_assert(sizeof(std::array<T, 0>) == sizeof(T[1]), "");
+ static_assert(sizeof(std::array<T, 0>) == sizeof(MyArray<T, 1>), "");
+ static_assert(alignof(std::array<T, 0>) == alignof(MyArray<T, 1>), "");
+ }
+
+ {
+ static_assert(sizeof(std::array<T, 1>) == sizeof(T), "");
+ static_assert(alignof(std::array<T, 1>) == alignof(T), "");
+ static_assert(sizeof(std::array<T, 1>) == sizeof(T[1]), "");
+ static_assert(sizeof(std::array<T, 1>) == sizeof(MyArray<T, 1>), "");
+ static_assert(alignof(std::array<T, 1>) == alignof(MyArray<T, 1>), "");
+ }
+
+ {
+ static_assert(sizeof(std::array<T, 2>) == sizeof(T) * 2, "");
+ static_assert(alignof(std::array<T, 2>) == alignof(T), "");
+ static_assert(sizeof(std::array<T, 2>) == sizeof(T[2]), "");
+ static_assert(sizeof(std::array<T, 2>) == sizeof(MyArray<T, 2>), "");
+ static_assert(alignof(std::array<T, 2>) == alignof(MyArray<T, 2>), "");
+ }
+
+ {
+ static_assert(sizeof(std::array<T, 3>) == sizeof(T) * 3, "");
+ static_assert(alignof(std::array<T, 3>) == alignof(T), "");
+ static_assert(sizeof(std::array<T, 3>) == sizeof(T[3]), "");
+ static_assert(sizeof(std::array<T, 3>) == sizeof(MyArray<T, 3>), "");
+ static_assert(alignof(std::array<T, 3>) == alignof(MyArray<T, 3>), "");
+ }
+
+ {
+ static_assert(sizeof(std::array<T, 444>) == sizeof(T) * 444, "");
+ static_assert(alignof(std::array<T, 444>) == alignof(T), "");
+ static_assert(sizeof(std::array<T, 444>) == sizeof(T[444]), "");
+ static_assert(sizeof(std::array<T, 444>) == sizeof(MyArray<T, 444>), "");
+ static_assert(alignof(std::array<T, 444>) == alignof(MyArray<T, 444>), "");
+ }
+}
+
+struct Empty {};
+
+struct Aggregate {
+ int i;
+};
+
+struct WithPadding {
+ long double ld;
+ char c;
+};
+
+#if TEST_STD_VER >= 11
+struct alignas(alignof(std::max_align_t) * 2) Overaligned1 {};
+
+struct alignas(alignof(std::max_align_t) * 2) Overaligned2 {
+ char data[1000];
+};
+
+struct alignas(alignof(std::max_align_t)) Overaligned3 {
+ char data[1000];
+};
+
+struct alignas(8) Overaligned4 {
+ char c;
+};
+
+struct alignas(8) Overaligned5 {};
+#endif
+
+int main(int, char**) {
----------------
mordante wrote:
Maybe remain `main` to `test` since it's a compile only test.
https://github.com/llvm/llvm-project/pull/74667
More information about the libcxx-commits
mailing list