From 7ad3e3c7bb86f10f60e6efbec587391c89c191fd Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:07:19 -0400 Subject: [PATCH] bit_field: Left/right shifts are well defined in C++20 --- src/common/new_bit_field.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/new_bit_field.h b/src/common/new_bit_field.h index 30acaeb288..d32ff9da10 100644 --- a/src/common/new_bit_field.h +++ b/src/common/new_bit_field.h @@ -175,6 +175,10 @@ constexpr OutputType ExtractBits(const RawType& raw) { static_assert(sizeof(RawType) == sizeof(SignedType)); constexpr auto RightShift = BitSize() - NumBits; constexpr auto LeftShift = RightShift - Position; + // C++20: Signed Integers are Two’s Complement + // Left-shift on signed integer types produces the same results as + // left-shift on the corresponding unsigned integer type. + // Right-shift is an arithmetic right shift which performs sign-extension. return AutoBitCast((AutoBitCast(raw) << LeftShift) >> RightShift); } else { using UnsignedType = SmallestUIntType()>;