From fa124e657f62863ec1f03a8da230602d358abc9f Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 7 Mar 2021 12:55:53 -0800 Subject: [PATCH] EnumFormatter: fix signed/unsigned comparison warnings --- Source/Core/Common/EnumFormatter.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/EnumFormatter.h b/Source/Core/Common/EnumFormatter.h index 2ca1bb114e..3f8d4d598b 100644 --- a/Source/Core/Common/EnumFormatter.h +++ b/Source/Core/Common/EnumFormatter.h @@ -60,22 +60,23 @@ public: template auto format(const T& e, FormatContext& ctx) { - const auto value = static_cast>(e); + const auto value_s = static_cast>(e); // Possibly signed + const auto value_u = static_cast>(value_s); // Always unsigned + const bool has_name = value_s >= 0 && value_u < size && m_names[value_u] != nullptr; if (!formatting_for_shader) { - if (value >= 0 && value < size && m_names[value] != nullptr) - return fmt::format_to(ctx.out(), "{} ({})", m_names[value], value); + if (has_name) + return fmt::format_to(ctx.out(), "{} ({})", m_names[value_u], value_s); else - return fmt::format_to(ctx.out(), "Invalid ({})", value); + return fmt::format_to(ctx.out(), "Invalid ({})", value_s); } else { - if (value >= 0 && value < size && m_names[value] != nullptr) - return fmt::format_to(ctx.out(), "{:#x}u /* {} */", value, m_names[value]); + if (has_name) + return fmt::format_to(ctx.out(), "{:#x}u /* {} */", value_u, m_names[value_u]); else - return fmt::format_to(ctx.out(), "{:#x}u /* Invalid */", - static_cast>(value)); + return fmt::format_to(ctx.out(), "{:#x}u /* Invalid */", value_u); } }