Skip to content

Commit ccb08b9

Browse files
authored
[libc++] Also provide an alignment assumption for vector in C++03 mode (llvm#124839)
There's no reason not to, and it's easy enough to do using enable_if. As a drive-by change, also add a missing _LIBCPP_NO_CFI attribute on __add_alignment_assumption.
1 parent 8c36665 commit ccb08b9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

libcxx/include/__vector/vector.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -783,14 +783,18 @@ class _LIBCPP_TEMPLATE_VIS vector {
783783

784784
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
785785

786-
static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __add_alignment_assumption(pointer __p) _NOEXCEPT {
787-
#ifndef _LIBCPP_CXX03_LANG
788-
if constexpr (is_pointer<pointer>::value) {
789-
if (!__libcpp_is_constant_evaluated()) {
790-
return static_cast<pointer>(__builtin_assume_aligned(__p, alignof(decltype(*__p))));
791-
}
786+
template <class _Ptr = pointer, __enable_if_t<is_pointer<_Ptr>::value, int> = 0>
787+
static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
788+
__add_alignment_assumption(_Ptr __p) _NOEXCEPT {
789+
if (!__libcpp_is_constant_evaluated()) {
790+
return static_cast<pointer>(__builtin_assume_aligned(__p, _LIBCPP_ALIGNOF(decltype(*__p))));
792791
}
793-
#endif
792+
return __p;
793+
}
794+
795+
template <class _Ptr = pointer, __enable_if_t<!is_pointer<_Ptr>::value, int> = 0>
796+
static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
797+
__add_alignment_assumption(_Ptr __p) _NOEXCEPT {
794798
return __p;
795799
}
796800
};

0 commit comments

Comments
 (0)