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 #include <array>
17 #include <iterator>
18 #include <type_traits>
19 #include <cstddef>
20 
21 #include "test_macros.h"
22 
23 
24 template <class T, size_t Size>
25 struct MyArray {
26   T elems[Size];
27 };
28 
29 template <class T, size_t Size>
test()30 void test() {
31   typedef T CArrayT[Size == 0 ? 1 : Size];
32   typedef std::array<T, Size> ArrayT;
33   typedef MyArray<T, Size == 0 ? 1 : Size> MyArrayT;
34   static_assert(sizeof(ArrayT) == sizeof(CArrayT), "");
35   static_assert(sizeof(ArrayT) == sizeof(MyArrayT), "");
36   static_assert(TEST_ALIGNOF(ArrayT) == TEST_ALIGNOF(MyArrayT), "");
37 }
38 
39 template <class T>
test_type()40 void test_type() {
41   test<T, 1>();
42   test<T, 42>();
43   test<T, 0>();
44 }
45 
46 #if TEST_STD_VER >= 11
47 struct alignas(alignof(std::max_align_t) * 2) TestType1 {
48 
49 };
50 
51 struct alignas(alignof(std::max_align_t) * 2) TestType2 {
52   char data[1000];
53 };
54 
55 struct alignas(alignof(std::max_align_t)) TestType3 {
56   char data[1000];
57 };
58 #endif
59 
main(int,char **)60 int main(int, char**) {
61   test_type<char>();
62   test_type<int>();
63   test_type<double>();
64   test_type<long double>();
65 
66 #if TEST_STD_VER >= 11
67   test_type<std::max_align_t>();
68   test_type<TestType1>();
69   test_type<TestType2>();
70   test_type<TestType3>();
71 #endif
72 
73   return 0;
74 }
75