mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 16:48:06 +02:00
Avoid clang 10 -Wimplicit-int-float-conversion warning/error when converting int into float (#2943)
Example of warning (error when using -Werror) we get with clang 10: /remote/intdeliv/components/osp/Poco/Foundation/19-0-0-6/include/Poco/Dynamic/VarHolder.h:444:14: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion] if (from > std::numeric_limits<T>::max()) ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /remote/intdeliv/components/osp/Poco/Foundation/19-0-0-6/include/Poco/Dynamic/VarHolder.h:332:4: note: in instantiation of function template specialization 'Poco::Dynamic::VarHolder::checkUpperLimitFloat<float, int>' requested here checkUpperLimitFloat<F,T>(from); ^ /remote/intdeliv/components/osp/Poco/Foundation/19-0-0-6/include/Poco/Dynamic/VarHolder.h:2175:3: note: in instantiation of function template specialization 'Poco::Dynamic::VarHolder::convertToSmaller<float, int>' requested here convertToSmaller(_val, val); ^
This commit is contained in:

committed by
GitHub

parent
b52ec8cc47
commit
75eb0ca7cb
@@ -425,15 +425,33 @@ private:
|
|||||||
template <typename F, typename T>
|
template <typename F, typename T>
|
||||||
void checkUpperLimitFloat(const F& from) const
|
void checkUpperLimitFloat(const F& from) const
|
||||||
{
|
{
|
||||||
if (from > std::numeric_limits<T>::max())
|
if (std::is_floating_point<T>::value)
|
||||||
throw RangeException("Value too large.");
|
{
|
||||||
|
if (from > std::numeric_limits<T>::max())
|
||||||
|
throw RangeException("Value too large.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Avoid clang -Wimplicit-int-float-conversion warning with an explicit cast.
|
||||||
|
if (from > static_cast<F>(std::numeric_limits<T>::max()))
|
||||||
|
throw RangeException("Value too large.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F, typename T>
|
template <typename F, typename T>
|
||||||
void checkLowerLimitFloat(const F& from) const
|
void checkLowerLimitFloat(const F& from) const
|
||||||
{
|
{
|
||||||
if (from < -std::numeric_limits<T>::max())
|
if (std::is_floating_point<T>::value)
|
||||||
throw RangeException("Value too small.");
|
{
|
||||||
|
if (from < -std::numeric_limits<T>::max())
|
||||||
|
throw RangeException("Value too small.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Avoid clang -Wimplicit-int-float-conversion warning with an explicit cast.
|
||||||
|
if (from < static_cast<F>(std::numeric_limits<T>::min()))
|
||||||
|
throw RangeException("Value too small.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F, typename T>
|
template <typename F, typename T>
|
||||||
|
Reference in New Issue
Block a user