http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57350
--- Comment #9 from David Krauss <potswa at mac dot com> --- Whoa, there's a nasty bug there, if alignment > space. inline void *align( std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space ) { std::uintptr_t pn = reinterpret_cast< std::uintptr_t >( ptr ); std::uintptr_t aligned = ( pn + alignment - 1 ) & - alignment; size += aligned - pn; // Add padding to size. if ( space < size ) return nullptr; space -= size; return ptr = reinterpret_cast< void * >( aligned ); } I haven't tested this edit at all.