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