brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 6631895 Raw
56 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// type_traits10 11// alignment_of12 13#include <type_traits>14#include <cstdint>15 16#include "test_macros.h"17 18template <class T, unsigned A>19void 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 > 1429    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#endif34}35 36class Class37{38public:39    ~Class();40};41 42int 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}56