From 10cfa87eb685173c493bc480d4444694361e3c39 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 15 Apr 2019 12:35:50 -0400 Subject: [PATCH] common/alignment: Apply nodiscard and noexcept to utility functions In all scenarios, ignoring the return value of these functions is a bug. While we're at it, we can also make them noexcept. --- src/common/alignment.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/alignment.h b/src/common/alignment.h index d94a2291f7..39daf67544 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -8,25 +8,25 @@ namespace Common { template -constexpr T AlignUp(T value, std::size_t size) { +[[nodiscard]] constexpr T AlignUp(T value, std::size_t size) noexcept { static_assert(std::is_unsigned_v, "T must be an unsigned value."); return static_cast(value + (size - value % size) % size); } template -constexpr T AlignDown(T value, std::size_t size) { +[[nodiscard]] constexpr T AlignDown(T value, std::size_t size) noexcept { static_assert(std::is_unsigned_v, "T must be an unsigned value."); return static_cast(value - value % size); } template -constexpr bool Is4KBAligned(T value) { +[[nodiscard]] constexpr bool Is4KBAligned(T value) noexcept { static_assert(std::is_unsigned_v, "T must be an unsigned value."); return (value & 0xFFF) == 0; } template -constexpr bool IsWordAligned(T value) { +[[nodiscard]] constexpr bool IsWordAligned(T value) noexcept { static_assert(std::is_unsigned_v, "T must be an unsigned value."); return (value & 0b11) == 0; }