• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  //===----------------------------------------------------------------------===//
2  //
3  //                     The LLVM Compiler Infrastructure
4  //
5  // This file is dual licensed under the MIT and the University of Illinois Open
6  // Source Licenses. See LICENSE.TXT for details.
7  //
8  //===----------------------------------------------------------------------===//
9  
10  // type_traits
11  
12  // alignment_of
13  
14  #include <type_traits>
15  #include <cstdint>
16  
17  #include "test_macros.h"
18  
19  template <class T, unsigned A>
test_alignment_of()20  void test_alignment_of()
21  {
22      static_assert( std::alignment_of<T>::value == A, "");
23      static_assert( std::alignment_of<const T>::value == A, "");
24      static_assert( std::alignment_of<volatile T>::value == A, "");
25      static_assert( std::alignment_of<const volatile T>::value == A, "");
26  #if TEST_STD_VER > 14
27      static_assert( std::alignment_of_v<T> == A, "");
28      static_assert( std::alignment_of_v<const T> == A, "");
29      static_assert( std::alignment_of_v<volatile T> == A, "");
30      static_assert( std::alignment_of_v<const volatile T> == A, "");
31  #endif
32  }
33  
34  class Class
35  {
36  public:
37      ~Class();
38  };
39  
main()40  int main()
41  {
42      test_alignment_of<int&, 4>();
43      test_alignment_of<Class, 1>();
44      test_alignment_of<int*, sizeof(intptr_t)>();
45      test_alignment_of<const int*, sizeof(intptr_t)>();
46      test_alignment_of<char[3], 1>();
47      test_alignment_of<int, 4>();
48      test_alignment_of<double, 8>();
49  #if (defined(__ppc__) && !defined(__ppc64__))
50      test_alignment_of<bool, 4>();   // 32-bit PPC has four byte bool
51  #else
52      test_alignment_of<bool, 1>();
53  #endif
54      test_alignment_of<unsigned, 4>();
55  }
56