From 4f012e9b14a70786ff7bb7ed718a3225e1529309 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 7 Nov 2026 08:33:18 +0000 Subject: [PATCH] Tests: sweep_allocator::construct() accepts pointers to const Recent libc++ (emsdk latest) probes construct(const T*, const T&) in an unevaluated context while checking for trivial copies; the static_cast to void* in the noexcept specification then fails to compile. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01N5NasEsrzHhSNouxSoEwqz (cherry picked from commit 794bf70823c12a2a1cb2a8a95f34dfb6357746a8) Signed-off-by: Niels Lohmann --- tests/src/unit-allocator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index 8fa9034b5..ca215751e 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -1073,10 +1073,12 @@ struct sweep_allocator return (std::numeric_limits::max)() / sizeof(T); } + // p may point to a const object when libc++ probes whether construct() is + // usable for copying, which static_cast(p) would not accept template - void construct(U* p, Args&& ... args) noexcept(noexcept(::new (static_cast(p)) U(std::forward(args)...))) + void construct(U* p, Args&& ... args) noexcept(noexcept(::new (const_cast(static_cast(p))) U(std::forward(args)...))) { - ::new (static_cast(p)) U(std::forward(args)...); + ::new (const_cast(static_cast(p))) U(std::forward(args)...); } template