diff options
| author | 2020-08-14 09:38:45 -0400 | |
|---|---|---|
| committer | 2020-08-15 17:17:52 -0400 | |
| commit | df7248039553b3ebd338380c3ef0428b0e046e79 (patch) | |
| tree | eca7153300e311ac7954f5c085fdada0c7295699 /src/common/bit_field.h | |
| parent | Merge pull request #4526 from lioncash/core-semi (diff) | |
| download | yuzu-df7248039553b3ebd338380c3ef0428b0e046e79.tar.gz yuzu-df7248039553b3ebd338380c3ef0428b0e046e79.tar.xz yuzu-df7248039553b3ebd338380c3ef0428b0e046e79.zip | |
common: Make use of [[nodiscard]] where applicable
Now that clang-format makes [[nodiscard]] attributes format sensibly, we
can apply them to several functions within the common library to allow
the compiler to complain about any misuses of the functions.
Diffstat (limited to '')
| -rw-r--r-- | src/common/bit_field.h | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 26ae6c7fc..0f0661172 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -36,13 +36,6 @@ | |||
| 36 | #include "common/common_funcs.h" | 36 | #include "common/common_funcs.h" |
| 37 | #include "common/swap.h" | 37 | #include "common/swap.h" |
| 38 | 38 | ||
| 39 | // Inlining | ||
| 40 | #ifdef _WIN32 | ||
| 41 | #define FORCE_INLINE __forceinline | ||
| 42 | #else | ||
| 43 | #define FORCE_INLINE inline __attribute__((always_inline)) | ||
| 44 | #endif | ||
| 45 | |||
| 46 | /* | 39 | /* |
| 47 | * Abstract bitfield class | 40 | * Abstract bitfield class |
| 48 | * | 41 | * |
| @@ -142,8 +135,8 @@ public: | |||
| 142 | * containing several bitfields can be assembled by formatting each of their values and ORing | 135 | * containing several bitfields can be assembled by formatting each of their values and ORing |
| 143 | * the results together. | 136 | * the results together. |
| 144 | */ | 137 | */ |
| 145 | static constexpr FORCE_INLINE StorageType FormatValue(const T& value) { | 138 | [[nodiscard]] static constexpr StorageType FormatValue(const T& value) { |
| 146 | return ((StorageType)value << position) & mask; | 139 | return (static_cast<StorageType>(value) << position) & mask; |
| 147 | } | 140 | } |
| 148 | 141 | ||
| 149 | /** | 142 | /** |
| @@ -151,7 +144,7 @@ public: | |||
| 151 | * (such as Value() or operator T), but this can be used to extract a value from a bitfield | 144 | * (such as Value() or operator T), but this can be used to extract a value from a bitfield |
| 152 | * union in a constexpr context. | 145 | * union in a constexpr context. |
| 153 | */ | 146 | */ |
| 154 | static constexpr FORCE_INLINE T ExtractValue(const StorageType& storage) { | 147 | [[nodiscard]] static constexpr T ExtractValue(const StorageType& storage) { |
| 155 | if constexpr (std::numeric_limits<UnderlyingType>::is_signed) { | 148 | if constexpr (std::numeric_limits<UnderlyingType>::is_signed) { |
| 156 | std::size_t shift = 8 * sizeof(T) - bits; | 149 | std::size_t shift = 8 * sizeof(T) - bits; |
| 157 | return static_cast<T>(static_cast<UnderlyingType>(storage << (shift - position)) >> | 150 | return static_cast<T>(static_cast<UnderlyingType>(storage << (shift - position)) >> |
| @@ -175,7 +168,7 @@ public: | |||
| 175 | constexpr BitField(BitField&&) noexcept = default; | 168 | constexpr BitField(BitField&&) noexcept = default; |
| 176 | constexpr BitField& operator=(BitField&&) noexcept = default; | 169 | constexpr BitField& operator=(BitField&&) noexcept = default; |
| 177 | 170 | ||
| 178 | constexpr operator T() const { | 171 | [[nodiscard]] constexpr operator T() const { |
| 179 | return Value(); | 172 | return Value(); |
| 180 | } | 173 | } |
| 181 | 174 | ||
| @@ -183,11 +176,11 @@ public: | |||
| 183 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); | 176 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); |
| 184 | } | 177 | } |
| 185 | 178 | ||
| 186 | constexpr T Value() const { | 179 | [[nodiscard]] constexpr T Value() const { |
| 187 | return ExtractValue(storage); | 180 | return ExtractValue(storage); |
| 188 | } | 181 | } |
| 189 | 182 | ||
| 190 | constexpr explicit operator bool() const { | 183 | [[nodiscard]] constexpr explicit operator bool() const { |
| 191 | return Value() != 0; | 184 | return Value() != 0; |
| 192 | } | 185 | } |
| 193 | 186 | ||