Adjust max_align_t handling

Depend on the compiler to provide a correct implementation of
max_align_t. If __STDCPP_NEW_ALIGNMENT__ is missing and C++03 mode has
been explicitly enabled, provide a minimal fallback in <new> as
alignment of the largest primitive types.
This commit is contained in:
Joerg Sonnenberger 2020-02-04 15:04:42 +01:00
parent e34ddc09f4
commit 03dd205c15
3 changed files with 12 additions and 12 deletions

View File

@ -25,7 +25,7 @@ Types:
ptrdiff_t
size_t
max_align_t
max_align_t // C++11
nullptr_t
byte // C++17
@ -49,12 +49,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
using ::ptrdiff_t;
using ::size_t;
#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
defined(__DEFINED_max_align_t) || defined(__NetBSD__)
// Re-use the compiler's <stddef.h> max_align_t where possible.
#if !defined(_LIBCPP_CXX03_LANG)
using ::max_align_t;
#else
typedef long double max_align_t;
#endif
template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };

View File

@ -226,9 +226,19 @@ inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT
_LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_LIBCPP_CXX03_LANG)
union __libcpp_max_align_t {
void * __f1;
long long int __f2;
long double __f3;
};
#endif
_LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
#elif defined(_LIBCPP_CXX03_LANG)
return __align > alignment_of<__libcpp_max_align_t>::value;
#else
return __align > alignment_of<max_align_t>::value;
#endif

View File

@ -51,12 +51,6 @@ extern "C++" {
using std::nullptr_t;
}
// Re-use the compiler's <stddef.h> max_align_t where possible.
#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) && \
!defined(__DEFINED_max_align_t) && !defined(__NetBSD__)
typedef long double max_align_t;
#endif
#endif
#endif // _LIBCPP_STDDEF_H