Give static analysis some hints
Static analysis tools complain that for certain template types, these
comparisons do nothing. Doing nothing is what they're intended to do,
as we have other checks.
Add some constexpr if hints so static analysis tools don't complain.
Change-Id: I60297d094626936d021382ccdc11e4c8b698e3d8
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index df0c86e..d7d87a6 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -106,20 +106,9 @@
};
template <typename ToType, typename FromType>
-bool checkRange(const FromType& from, std::string_view key)
+bool checkRange(const FromType& from [[maybe_unused]],
+ std::string_view key [[maybe_unused]])
{
- if (from > std::numeric_limits<ToType>::max())
- {
- BMCWEB_LOG_DEBUG("Value for key {} was greater than max: {}", key,
- __PRETTY_FUNCTION__);
- return false;
- }
- if (from < std::numeric_limits<ToType>::lowest())
- {
- BMCWEB_LOG_DEBUG("Value for key {} was less than min: {}", key,
- __PRETTY_FUNCTION__);
- return false;
- }
if constexpr (std::is_floating_point_v<ToType>)
{
if (std::isnan(from))
@@ -128,6 +117,26 @@
return false;
}
}
+ if constexpr (std::numeric_limits<ToType>::max() <
+ std::numeric_limits<FromType>::max())
+ {
+ if (from > std::numeric_limits<ToType>::max())
+ {
+ BMCWEB_LOG_DEBUG("Value for key {} was greater than max {}", key,
+ std::numeric_limits<FromType>::max());
+ return false;
+ }
+ }
+ if constexpr (std::numeric_limits<ToType>::lowest() >
+ std::numeric_limits<FromType>::lowest())
+ {
+ if (from < std::numeric_limits<ToType>::lowest())
+ {
+ BMCWEB_LOG_DEBUG("Value for key {} was less than min {}", key,
+ std::numeric_limits<FromType>::lowest());
+ return false;
+ }
+ }
return true;
}