Преглед изворни кода

Merge pull request #3106 from lioncash/bitfield

common/bit_field: Silence sign-conversion warnings
Rodrigo Locatti пре 6 година
родитељ
комит
3026aec9bd
1 измењених фајлова са 3 додато и 2 уклоњено
  1. 3 2
      src/common/bit_field.h

+ 3 - 2
src/common/bit_field.h

@@ -135,7 +135,8 @@ public:
     /// Constants to allow limited introspection of fields if needed
     static constexpr std::size_t position = Position;
     static constexpr std::size_t bits = Bits;
-    static constexpr StorageType mask = (((StorageType)~0) >> (8 * sizeof(T) - bits)) << position;
+    static constexpr StorageType mask = StorageType(
+        (std::numeric_limits<StorageType>::max() >> (8 * sizeof(T) - bits)) << position);
 
     /**
      * Formats a value by masking and shifting it according to the field parameters. A value
@@ -143,7 +144,7 @@ public:
      * the results together.
      */
     static constexpr FORCE_INLINE StorageType FormatValue(const T& value) {
-        return ((StorageType)value << position) & mask;
+        return (static_cast<StorageType>(value) << position) & mask;
     }
 
     /**