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 // Test that _LIBCPP_ALIGNOF acts the same as the C++11 keyword `alignof`, and 10 // not as the GNU extension `__alignof`. The former returns the minimal required 11 // alignment for a type, whereas the latter returns the preferred alignment. 12 // 13 // See llvm.org/PR39713 14 15 #include <type_traits> 16 #include "test_macros.h" 17 18 template <class T> test()19void test() { 20 static_assert(_LIBCPP_ALIGNOF(T) == std::alignment_of<T>::value, ""); 21 static_assert(_LIBCPP_ALIGNOF(T) == TEST_ALIGNOF(T), ""); 22 #if TEST_STD_VER >= 11 23 static_assert(_LIBCPP_ALIGNOF(T) == alignof(T), ""); 24 #endif 25 #ifdef TEST_COMPILER_CLANG 26 static_assert(_LIBCPP_ALIGNOF(T) == _Alignof(T), ""); 27 #endif 28 } 29 main(int,char **)30int main(int, char**) { 31 test<int>(); 32 test<long long>(); 33 test<double>(); 34 test<long double>(); 35 return 0; 36 } 37