Skip to content

Commit 03dd205

Browse files
committed
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.
1 parent e34ddc0 commit 03dd205

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

libcxx/include/cstddef

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Types:
2525
2626
ptrdiff_t
2727
size_t
28-
max_align_t
28+
max_align_t // C++11
2929
nullptr_t
3030
byte // C++17
3131
@@ -49,12 +49,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4949
using ::ptrdiff_t;
5050
using ::size_t;
5151

52-
#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
53-
defined(__DEFINED_max_align_t) || defined(__NetBSD__)
54-
// Re-use the compiler's <stddef.h> max_align_t where possible.
52+
#if !defined(_LIBCPP_CXX03_LANG)
5553
using ::max_align_t;
56-
#else
57-
typedef long double max_align_t;
5854
#endif
5955

6056
template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };

libcxx/include/new

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,19 @@ inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT
226226

227227
_LIBCPP_BEGIN_NAMESPACE_STD
228228

229+
#if defined(_LIBCPP_CXX03_LANG)
230+
union __libcpp_max_align_t {
231+
void * __f1;
232+
long long int __f2;
233+
long double __f3;
234+
};
235+
#endif
236+
229237
_LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
230238
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
231239
return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
240+
#elif defined(_LIBCPP_CXX03_LANG)
241+
return __align > alignment_of<__libcpp_max_align_t>::value;
232242
#else
233243
return __align > alignment_of<max_align_t>::value;
234244
#endif

libcxx/include/stddef.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ extern "C++" {
5151
using std::nullptr_t;
5252
}
5353

54-
// Re-use the compiler's <stddef.h> max_align_t where possible.
55-
#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) && \
56-
!defined(__DEFINED_max_align_t) && !defined(__NetBSD__)
57-
typedef long double max_align_t;
58-
#endif
59-
6054
#endif
6155

6256
#endif // _LIBCPP_STDDEF_H

0 commit comments

Comments
 (0)