Move internal usages of alignof/__alignof to use _LIBCPP_ALIGNOF.
Summary: Starting in Clang 8.0 and GCC 8.0, `alignof` and `__alignof` return different values in same cases. Specifically `alignof` and `_Alignof` return the minimum alignment for a type, where as `__alignof` returns the preferred alignment. libc++ currently uses `__alignof` but means to use `alignof`. See llvm.org/PR39713 This patch introduces the macro `_LIBCPP_ALIGNOF` so we can control which spelling gets used. This patch does not introduce any ABI guard to provide the old behavior with newer compilers. However, if we decide that is needed, this patch makes it trivial to implement. I think we should commit this change immediately, and decide what we want to do about the ABI afterwards. Reviewers: ldionne, EricWF Reviewed By: EricWF Subscribers: christof, libcxx-commits Differential Revision: https://reviews.llvm.org/D54814 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@347787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
38
test/libcxx/libcpp_alignof.pass.cpp
Normal file
38
test/libcxx/libcpp_alignof.pass.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Test that _LIBCPP_ALIGNOF acts the same as the C++11 keyword `alignof`, and
|
||||
// not as the GNU extension `__alignof`. The former returns the minimal required
|
||||
// alignment for a type, whereas the latter returns the preferred alignment.
|
||||
//
|
||||
// See llvm.org/PR39713
|
||||
|
||||
#include <type_traits>
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class T>
|
||||
void test() {
|
||||
static_assert(_LIBCPP_ALIGNOF(T) == std::alignment_of<T>::value, "");
|
||||
static_assert(_LIBCPP_ALIGNOF(T) == TEST_ALIGNOF(T), "");
|
||||
static_assert(alignof(T) == __alignof(T), "");
|
||||
#if TEST_STD_VER >= 11
|
||||
static_assert(_LIBCPP_ALIGNOF(T) == alignof(T), "");
|
||||
#endif
|
||||
#ifdef TEST_COMPILER_CLANG
|
||||
static_assert(_LIBCPP_ALIGNOF(T) == _Alignof(T), "");
|
||||
#endif
|
||||
}
|
||||
|
||||
int main() {
|
||||
test<int>();
|
||||
test<long long>();
|
||||
test<double>();
|
||||
test<long double>();
|
||||
}
|
||||
Reference in New Issue
Block a user