From 8ac7364a1623228e4c9a1eda73a4c733687d3399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 23 Dec 2025 22:37:16 +0100 Subject: [PATCH] Fix test for platforms where "weak-alignment" allocations are implemented, small allocations can't return alignment smaller than "max_align". --- test/new_delete_resource_test.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/new_delete_resource_test.cpp b/test/new_delete_resource_test.cpp index 85d0e59..edf2c52 100644 --- a/test/new_delete_resource_test.cpp +++ b/test/new_delete_resource_test.cpp @@ -67,7 +67,15 @@ void test_allocate_various_sizes() const std::size_t sz = sizes[i]; void* p = mr->allocate(sz); BOOST_TEST(p != 0); - BOOST_TEST(is_aligned(p, max_align)); + //See: + // WG14 N2293: Alignment requirements for memory management functions + // + //The alignment requirements of malloc, calloc, and realloc are ambiguously phrased for small + //allocations. The "strong-alignment" reading demands _Alignof(max_align_t) alignment regardless + //of size, while the "weak-alignment" reading requires only enough alignment to accommodate + //types that could fit in the allocated memory—meaning small allocations need only align to the largest + //power of two not exceeding the requested size. Many implementations use weak alignment + BOOST_TEST(is_aligned(p, sz < max_align ? sz : max_align)); // Write to allocated memory std::memset(p, 0xCD, sz);