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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N5NasEsrzHhSNouxSoEwqz (cherry picked from commit de099fa607001b710862fd1bbecef3609c54cbc4) Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
1 file changed
+6
-5
@@ -14,6 +14,7 @@ using nlohmann::json;
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <type_traits>
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
#if JSON_HAS_RANGES
|
#if JSON_HAS_RANGES
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
@@ -1073,12 +1074,12 @@ struct sweep_allocator
|
|||||||
return (std::numeric_limits<std::size_t>::max)() / sizeof(T);
|
return (std::numeric_limits<std::size_t>::max)() / sizeof(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
// p may point to a const object when libc++ probes whether construct() is
|
// libc++ probes whether construct() is usable for const objects (when
|
||||||
// usable for copying, which static_cast<void*>(p) would not accept
|
// checking for trivial copies); this must not be viable then
|
||||||
template<class U, class... Args>
|
template<class U, class... Args, typename = typename std::enable_if<!std::is_const<U>::value>::type>
|
||||||
void construct(U* p, Args&& ... args) noexcept(noexcept(::new (const_cast<void*>(static_cast<const volatile void*>(p))) U(std::forward<Args>(args)...)))
|
void construct(U* p, Args&& ... args) noexcept(noexcept(::new (static_cast<void*>(p)) U(std::forward<Args>(args)...)))
|
||||||
{
|
{
|
||||||
::new (const_cast<void*>(static_cast<const volatile void*>(p))) U(std::forward<Args>(args)...);
|
::new (static_cast<void*>(p)) U(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
|
|||||||
Reference in new issue
Block a user