// Copyright 2023 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include template struct struct_of { T t; }; template union union_of { T t; }; template void test2() { BOOST_TEST_EQ( BOOST_CORE_ALIGNOF(T), boost::alignment_of::value ); #if !defined(BOOST_NO_CXX11_ALIGNOF) BOOST_TEST_EQ( BOOST_CORE_ALIGNOF(T), alignof(T) ); #endif } template void test() { test2(); test2(); test2< struct_of >(); test2< union_of >(); } struct X { }; int main() { test(); test(); test(); test(); #if !defined(BOOST_NO_LONG_LONG) # if !( defined(__GNUC__) && defined(__i386__) ) // g++ -m32 has alignof(long long) = 8, but boost::alignment_of::value = 4 test(); # endif #endif #if defined(BOOST_HAS_INT128) test(); #endif test(); #if !( defined(__GNUC__) && defined(__i386__) ) // g++ -m32 has alignof(double) = 8, but boost::alignment_of::value = 4 test(); #endif test(); #if defined(BOOST_HAS_FLOAT128) test<__float128>(); #endif test(); test(); #if !defined(_MSC_VER) // under MSVC, alignof is 8, boost::alignment_of is 4 // under clang-cl, alignof is 4, boost::alignment_of is 8 (!) test(); #endif test(); return boost::report_errors(); }