1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <array>
10
11 // template <class T, size_t N>
12 // struct array
13
14 // Test the size and alignment matches that of an array of a given type.
15
16 // Ignore error about requesting a large alignment not being ABI compatible with older AIX systems.
17 #if defined(_AIX)
18 # pragma clang diagnostic ignored "-Waix-compat"
19 #endif
20
21 #include <array>
22 #include <iterator>
23 #include <type_traits>
24 #include <cstddef>
25
26 #include "test_macros.h"
27
28 template <class T, size_t Size>
29 struct MyArray {
30 T elems[Size];
31 };
32
33 template <class T, size_t Size>
test()34 void test() {
35 typedef T CArrayT[Size == 0 ? 1 : Size];
36 typedef std::array<T, Size> ArrayT;
37 typedef MyArray<T, Size == 0 ? 1 : Size> MyArrayT;
38 static_assert(sizeof(ArrayT) == sizeof(CArrayT), "");
39 static_assert(sizeof(ArrayT) == sizeof(MyArrayT), "");
40 static_assert(TEST_ALIGNOF(ArrayT) == TEST_ALIGNOF(MyArrayT), "");
41 }
42
43 template <class T>
test_type()44 void test_type() {
45 test<T, 1>();
46 test<T, 42>();
47 test<T, 0>();
48 }
49
50 #if TEST_STD_VER >= 11
51 struct alignas(alignof(std::max_align_t) * 2) TestType1 {
52
53 };
54
55 struct alignas(alignof(std::max_align_t) * 2) TestType2 {
56 char data[1000];
57 };
58
59 struct alignas(alignof(std::max_align_t)) TestType3 {
60 char data[1000];
61 };
62 #endif
63
main(int,char **)64 int main(int, char**) {
65 test_type<char>();
66 test_type<int>();
67 test_type<double>();
68 test_type<long double>();
69
70 #if TEST_STD_VER >= 11
71 test_type<std::max_align_t>();
72 test_type<TestType1>();
73 test_type<TestType2>();
74 test_type<TestType3>();
75 #endif
76
77 return 0;
78 }
79