mirror of
https://github.com/boostorg/gil.git
synced 2026-02-21 03:02:10 +00:00
Merge pull request #143 from mloskot/ml/avoid-warnings-in-promote_integral
Add casts to avoid warnings due to implicit integral promotions
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
// - Remove support for boost::multiprecision types
|
||||
// - Remove support for 128-bit integer types
|
||||
// - Update and sort includes
|
||||
// - Add explicit conversions to avoid warnings due to implicit integral promotions
|
||||
//
|
||||
#include <boost/gil/promote_integral.hpp>
|
||||
|
||||
@@ -46,7 +47,7 @@ struct absolute_value
|
||||
{
|
||||
static inline T apply(T const& t)
|
||||
{
|
||||
return t < 0 ? -t : t;
|
||||
return static_cast<T>(t < 0 ? -t : t);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,11 +74,12 @@ struct test_max_values
|
||||
// but to avoid warning: comparing floating point with == is unsafe.
|
||||
|
||||
Promoted min_value = (std::numeric_limits<Integral>::min)();
|
||||
min_value *= min_value;
|
||||
// Explicit casts to avoid warning: conversion to short int from int may alter its value
|
||||
min_value = static_cast<Promoted>(min_value * min_value);
|
||||
BOOST_CHECK(absolute_value<Promoted>::apply(min_value) >= min_value);
|
||||
BOOST_CHECK(absolute_value<Promoted>::apply(min_value) <= min_value);
|
||||
Promoted max_value = (std::numeric_limits<Integral>::max)();
|
||||
max_value *= max_value;
|
||||
max_value = static_cast<Promoted>(max_value * max_value);
|
||||
BOOST_CHECK(absolute_value<Promoted>::apply(max_value) >= max_value);
|
||||
BOOST_CHECK(absolute_value<Promoted>::apply(max_value) <= max_value);
|
||||
|
||||
@@ -95,7 +97,7 @@ struct test_max_values<Integral, Promoted, false>
|
||||
static inline void apply()
|
||||
{
|
||||
Promoted max_value = (std::numeric_limits<Integral>::max)();
|
||||
Promoted max_value_sqr = max_value * max_value;
|
||||
Promoted max_value_sqr = static_cast<Promoted>(max_value * max_value);
|
||||
BOOST_CHECK(max_value_sqr < (std::numeric_limits<Promoted>::max)()
|
||||
&&
|
||||
max_value_sqr > max_value);
|
||||
|
||||
Reference in New Issue
Block a user