From 9bfdaa94c23adc2d1ae0d3c1b2fc66db8877202a Mon Sep 17 00:00:00 2001 From: templateU <1327746023@qq.com> Date: Thu, 12 Jun 2025 23:38:26 +0800 Subject: [PATCH] fix GCC Bug 57350: std::align missing --- include/boost/asio/detail/memory.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/boost/asio/detail/memory.hpp b/include/boost/asio/detail/memory.hpp index b6b4d44f3..ce3fe175d 100644 --- a/include/boost/asio/detail/memory.hpp +++ b/include/boost/asio/detail/memory.hpp @@ -55,7 +55,23 @@ inline const volatile T* to_address(const volatile T* p) { return p; } inline void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space) { +#if defined(__GNUC__) && __GNUC__ < 5 + // copy from g++11.4.0 + if (space < size) + return nullptr; + const auto __intptr = reinterpret_cast(ptr); + const auto __aligned = (__intptr - 1u + alignment) & -alignment; + const auto __diff = __aligned - __intptr; + if (__diff > (space - size)) + return nullptr; + else + { + space -= __diff; + return ptr = reinterpret_cast(__aligned); + } +#else return std::align(alignment, size, ptr, space); +#endif } } // namespace detail