From 609a2d3a49269a3292cd389482cc9c1535158eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Mon, 24 Sep 2018 11:11:01 +0200 Subject: [PATCH] Add casts to avoid warnings due to implicit integral promotions The explicit casts help to avoid warnings when integer types smaller than int are implicitly converted during arithmetic operations. --- test/promote_integral.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/promote_integral.cpp b/test/promote_integral.cpp index 4178ef812..590d5571e 100644 --- a/test/promote_integral.cpp +++ b/test/promote_integral.cpp @@ -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 @@ -46,7 +47,7 @@ struct absolute_value { static inline T apply(T const& t) { - return t < 0 ? -t : t; + return static_cast(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::min)(); - min_value *= min_value; + // Explicit casts to avoid warning: conversion to short int from int may alter its value + min_value = static_cast(min_value * min_value); BOOST_CHECK(absolute_value::apply(min_value) >= min_value); BOOST_CHECK(absolute_value::apply(min_value) <= min_value); Promoted max_value = (std::numeric_limits::max)(); - max_value *= max_value; + max_value = static_cast(max_value * max_value); BOOST_CHECK(absolute_value::apply(max_value) >= max_value); BOOST_CHECK(absolute_value::apply(max_value) <= max_value); @@ -95,7 +97,7 @@ struct test_max_values static inline void apply() { Promoted max_value = (std::numeric_limits::max)(); - Promoted max_value_sqr = max_value * max_value; + Promoted max_value_sqr = static_cast(max_value * max_value); BOOST_CHECK(max_value_sqr < (std::numeric_limits::max)() && max_value_sqr > max_value);