| 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 |
// type_traits |
| 10 |
|
| 11 |
// alignment_of |
| 12 |
|
| 13 |
#include <type_traits> |
| 14 |
#include <cstdint> |
| 15 |
|
| 16 |
#include "test_macros.h" |
| 17 |
|
| 18 |
template <class T, unsigned A> |
| 19 |
void test_alignment_of() |
| 20 |
{ |
| 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 |
| 34 |
} |
| 35 |
|
| 36 |
class Class |
| 37 |
{ |
| 38 |
public: |
| 39 |
~Class(); |
| 40 |
}; |
| 41 |
|
| 42 |
int main(int, char**) |
| 43 |
{ |
| 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>(); |
| 53 |
|
| 54 |
return 0; |
| 55 |
} |