[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / array / size_and_alignment.pass.cpp
blob11eac5cc825bbaa684e9e34048c4ae281bb1e0c4
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 //===----------------------------------------------------------------------===//
9 // <array>
11 // template <class T, size_t N >
12 // struct array
14 // Test the size and alignment matches that of an array of a given type.
16 #include <array>
17 #include <iterator>
18 #include <type_traits>
19 #include <cstddef>
21 #include "test_macros.h"
24 template <class T, size_t Size>
25 struct MyArray {
26 T elems[Size];
29 template <class T, size_t Size>
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), "");
39 template <class T>
40 void test_type() {
41 test<T, 1>();
42 test<T, 42>();
43 test<T, 0>();
46 #ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
47 struct TEST_ALIGNAS(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) TestType1 {
51 struct TEST_ALIGNAS(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) TestType2 {
52 char data[1000];
54 #else
55 struct TEST_ALIGNAS(TEST_ALIGNOF(std::max_align_t) * 2) TestType1 {
59 struct TEST_ALIGNAS(TEST_ALIGNOF(std::max_align_t) * 2) TestType2 {
60 char data[1000];
62 #endif
64 int main(int, char**) {
65 test_type<char>();
66 test_type<int>();
67 test_type<double>();
68 test_type<long double>();
70 #if TEST_STD_VER >= 11
71 test_type<std::max_align_t>();
72 #endif
73 test_type<TestType1>();
74 test_type<TestType2>();
76 return 0;