From 7c7b8dd41be35ec1c540356e039ef3692fc07732 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Mon, 16 Jun 2025 09:41:08 -0400 Subject: pkmacros: use a temporary value for bitwise NOT --- pkmacros.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkmacros.h b/pkmacros.h index 30144bd..5f50836 100644 --- a/pkmacros.h +++ b/pkmacros.h @@ -154,8 +154,8 @@ return a; \ }; \ TypeName operator~(TypeName& a) { \ - a = static_cast(~static_cast(a)); \ - return a; \ + TypeName_T b{static_cast(a)}; \ + return TypeName{static_cast(~b)}; \ }; #define TypeSafeInt_H(TypeName, Type, Max) \ TypeSafeInt2_H(TypeName, Type, Max, PK_CONCAT(TypeName, _T), PK_CONCAT(TypeName, _MAX), PK_CONCAT(TypeName, _T_MAX)) @@ -239,7 +239,8 @@ return a; \ }; \ constexpr TypeName operator~(const TypeName& a) { \ - return static_cast(~static_cast(a)); \ + TypeName_T b{static_cast(a)}; \ + return TypeName{static_cast(~b)}; \ }; #define TypeSafeInt_constexpr(TypeName, Type, Max) \ TypeSafeInt2_H_constexpr(TypeName, Type, Max, PK_CONCAT(TypeName, _T), PK_CONCAT(TypeName, _MAX), PK_CONCAT(TypeName, _T_MAX)) -- cgit v1.2.3