From e2eb9a7ddd43169ff629de4a58da46fcd12bcff1 Mon Sep 17 00:00:00 2001 From: Jody Hagins Date: Wed, 27 Aug 2025 15:10:18 -0400 Subject: [PATCH] Fix max_alignment bug segregator. The bug is a typo of max_alignment. This caused the SFINAE used in the allocator_traits to use the default max alignment because max_alignment wasn't defined. This meant that you could never get the right max alignment out of a sergregator composition. --- include/foonathan/memory/segregator.hpp | 2 +- test/segregator.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/foonathan/memory/segregator.hpp b/include/foonathan/memory/segregator.hpp index 101b82a..dab0de7 100644 --- a/include/foonathan/memory/segregator.hpp +++ b/include/foonathan/memory/segregator.hpp @@ -201,7 +201,7 @@ namespace foonathan return fallback_traits::max_array_size(get_fallback_allocator()); } - std::size_t max_alignemnt() const + std::size_t max_alignment() const { return fallback_traits::max_alignment(get_fallback_allocator()); } diff --git a/test/segregator.cpp b/test/segregator.cpp index 1d9fffe..a7c0a0d 100644 --- a/test/segregator.cpp +++ b/test/segregator.cpp @@ -170,3 +170,19 @@ TEST_CASE("segregator") REQUIRE(get_fallback_allocator(s).no_allocated() == 1u); s.deallocate_node(ptr, 17, 1); } + +TEST_CASE("binary_segregator max_alignment") +{ + struct allocator : test_allocator + { + std::size_t max_alignment() const noexcept + { + return std::size_t(4 * 1024); + } + }; + using segregatable = threshold_segregatable; + using segregator = binary_segregator; + + segregator s(threshold(8u, allocator{})); + REQUIRE(allocator_traits::max_alignment(s) == 4 * 1024u); +}