fix(VarHolder): MSVC warning #4886 (#4903)

* fix(VarHolder): MSVC warning #4886

* fix(VarHolder): do not convert unsigned #4886

* chore(SocketImpl): eliminate MSVC warning

* fix(VarHolder): do not convert unsigned (extract unpreserveSign()) #4886

* chore(testsuite): eliminate MSVC warnings

* chore(VarHolder): simplify unpreserveSign using constexpr.

---------

Co-authored-by: Matej Kenda <matejken@gmail.com>
This commit is contained in:
Aleksandar Fabijanic 2025-03-20 06:34:55 -05:00 committed by Matej Kenda
parent 1371c960e7
commit 4b093d8f89
6 changed files with 28 additions and 9 deletions

View File

@ -469,13 +469,32 @@ protected:
private:
template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
template <typename T>
static constexpr T unpreserveSign(const T& value)
{
if constexpr (std::is_signed_v<T>)
{
return (value < 0) ? -value : value;
}
else
{
return value;
}
}
template <typename T, std::enable_if_t<std::is_same_v<T, bool>, bool> = true>
static constexpr int numValDigits(const T& value)
{
return 1;
}
template <typename T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>, bool> = true>
static constexpr int numValDigits(const T& value)
{
using U = std::make_unsigned_t<T>;
if (value == 0) return 0;
int digitCount = 0;
U locVal = (std::is_signed_v<T> && value < 0) ? -value : value; // to prevent sign preservation
U locVal = static_cast<U>(unpreserveSign(value)); // to prevent sign preservation
while (locVal >>= 1) ++digitCount;
return digitCount;
}

View File

@ -400,7 +400,7 @@ int icompare(
typename S::size_type pos,
const typename S::value_type* ptr)
{
int n = pos < str.size() ? str.size() - pos : 0;
int n = static_cast<int>(pos < str.size() ? str.size() - pos : 0);
return icompare(str, pos, n, ptr);
}

View File

@ -60,7 +60,7 @@ void ArrayTest::testConstruction()
for (std::size_t i=0; i<g.size(); ++i)
{
g[i]._data = i;
g[i]._data = static_cast<int>(i);
}
for (std::size_t i=0; i<g.size(); ++i)

View File

@ -217,7 +217,7 @@ void CoreTest::testBuffer()
std::vector<int> v;
for (std::size_t i = 0; i < s; ++i)
{
v.push_back(i);
v.push_back(static_cast<int>(i));
}
std::memcpy(b.begin(), v.data(), sizeof(int) * v.size());
@ -241,7 +241,7 @@ void CoreTest::testBuffer()
v.clear();
for (std::size_t i = 0; i < s*2; ++i)
{
v.push_back(i);
v.push_back(static_cast<int>(i));
}
std::memcpy(b.begin(), v.data(), sizeof(int) * v.size());

View File

@ -277,7 +277,7 @@ void ProcessRunnerTest::testProcessRunner()
{
pr.reset(new ProcessRunner(cmd, args));
failmsg("ProcessRunner should throw an exception.");
} catch(const Poco::FileException& e) {}
} catch(const Poco::FileException&) {}
}
assertTrue (!File(pidFile).exists());
}
@ -295,7 +295,7 @@ void ProcessRunnerTest::testProcessRunner()
{
pr.reset(new ProcessRunner(cmd, args));
failmsg("ProcessRunner should throw an exception.");
} catch(const Poco::FileException& e) {}
} catch(const Poco::FileException&) {}
}
assertTrue (!File(pidFile).exists());
}

View File

@ -1566,7 +1566,7 @@ std::streamsize SocketImpl::sendFileBlockwise(FileInputStream& fileInputStream,
while (n > 0 && (count == 0 || len < count))
{
len += n;
sendBytes(buffer.begin(), n);
sendBytes(buffer.begin(), static_cast<int>(n));
if (count > 0 && len < count)
{
const std::size_t remaining = count - len;