From 8b70bf87679c647c8b5d0e706f3d3fd3ff077811 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 7 Nov 2026 08:33:18 +0000 Subject: [PATCH] Tests: guard sweep_allocator::construct() against const types instead of const_cast The const_cast added in the previous commit is rejected by cppcoreguidelines-pro-type-const-cast (clang-tidy). Make construct() not viable for const U instead, which is what libc++ probes for. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01N5NasEsrzHhSNouxSoEwqz (cherry picked from commit de099fa607001b710862fd1bbecef3609c54cbc4) Signed-off-by: Niels Lohmann --- tests/src/unit-allocator.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index ca215751e..3c719bf26 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -14,6 +14,7 @@ using nlohmann::json; #include #include +#include #include #if JSON_HAS_RANGES #include @@ -1073,12 +1074,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 (const_cast(static_cast(p))) U(std::forward(args)...))) + // libc++ probes whether construct() is usable for const objects (when + // checking for trivial copies); this must not be viable then + template::value>::type> + void construct(U* p, Args&& ... args) noexcept(noexcept(::new (static_cast(p)) U(std::forward(args)...))) { - ::new (const_cast(static_cast(p))) U(std::forward(args)...); + ::new (static_cast(p)) U(std::forward(args)...); } template