[mlir] Update Ch-2.md (#121379)
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.unary.prop.query / alignment_of.pass.cpp
blob66318951a8c975fe49896eaf048b8972d1204a6f
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 // type_traits
11 // alignment_of
13 #include <type_traits>
14 #include <cstdint>
16 #include "test_macros.h"
18 template <class T, unsigned A>
19 void test_alignment_of()
21 const unsigned AlignofResult = TEST_ALIGNOF(T);
22 static_assert( AlignofResult == A, "Golden value does not match result of alignof keyword");
23 static_assert( std::alignment_of<T>::value == AlignofResult, "");
24 static_assert( std::alignment_of<T>::value == A, "");
25 static_assert( std::alignment_of<const T>::value == A, "");
26 static_assert( std::alignment_of<volatile T>::value == A, "");
27 static_assert( std::alignment_of<const volatile T>::value == A, "");
28 #if TEST_STD_VER > 14
29 static_assert( std::alignment_of_v<T> == A, "");
30 static_assert( std::alignment_of_v<const T> == A, "");
31 static_assert( std::alignment_of_v<volatile T> == A, "");
32 static_assert( std::alignment_of_v<const volatile T> == A, "");
33 #endif
36 class Class
38 public:
39 ~Class();
42 int main(int, char**)
44 test_alignment_of<int&, 4>();
45 test_alignment_of<Class, 1>();
46 test_alignment_of<int*, sizeof(std::intptr_t)>();
47 test_alignment_of<const int*, sizeof(std::intptr_t)>();
48 test_alignment_of<char[3], 1>();
49 test_alignment_of<int, 4>();
50 test_alignment_of<double, TEST_ALIGNOF(double)>();
51 test_alignment_of<bool, 1>();
52 test_alignment_of<unsigned, 4>();
54 return 0;