From 8b0bc70db73b48d833a3b5791e55921768cf6932 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Mon, 31 Mar 2025 08:33:08 -0500 Subject: Remove reinterpret_cast usage in favor of std::bit_cast. --- include/fud_memory.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'include/fud_memory.hpp') diff --git a/include/fud_memory.hpp b/include/fud_memory.hpp index 6f6816f..bb60ab7 100644 --- a/include/fud_memory.hpp +++ b/include/fud_memory.hpp @@ -79,7 +79,7 @@ constexpr void zeroObject(T& object) static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); - auto* objPtr = reinterpret_cast(&object); + auto* objPtr = std::bit_cast(&object); for (size_t idx = 0; idx < sizeof(object); ++idx) { objPtr[idx] = 0; } @@ -95,10 +95,8 @@ void copyMem(T& destination, const U& source) static_assert(std::is_trivially_copyable_v); static_assert(std::is_trivially_copyable_v); - // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) - auto* destPtr = reinterpret_cast(&destination); - const auto* srcPtr = reinterpret_cast(&source); - // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) + auto* destPtr = std::bit_cast(&destination); + const auto* srcPtr = std::bit_cast(&source); for (size_t idx = 0; idx < Count; ++idx) { destPtr[idx] = srcPtr[idx]; @@ -121,9 +119,7 @@ int compareMem(const T& lhs, const U& rhs) int difference = 0; for (size_t idx = 0; idx < Count; ++idx) { - // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) - difference = reinterpret_cast(&lhs)[idx] - reinterpret_cast(&rhs)[idx]; - // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) + difference = std::bit_cast(&lhs)[idx] - std::bit_cast(&rhs)[idx]; if (difference != 0) { break; } @@ -142,9 +138,7 @@ int compareMem(const T& lhs, U&& rhs) int difference = 0; for (size_t idx = 0; idx < Count; ++idx) { - // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) - difference = reinterpret_cast(&lhs)[idx] - reinterpret_cast(&uRhs)[idx]; - // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) + difference = std::bit_cast(&lhs)[idx] - std::bit_cast(&uRhs)[idx]; if (difference != 0) { break; } -- cgit v1.2.3