Do not trigger -Wimplicit-int-float-conversion

This is mentioned in bug 10893 (comment 5).

clang 10.0.0 compiler triggered a warning pointing to the
changed lines. The issue there is the implicit conversion
that takes place in the comparison between 'result' and the max value,
which will result in a change of value for the cast operand.
This is expected, therefore explicitly cast the said constants
in order to make clear the intent and prevent such warnings from
popping up in the future.

Bug: webrtc:10893
Change-Id: Icb5cde84d1a5c7b5e4f4cd4b7b923de894cede87
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173140
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31041}
This commit is contained in:
mmorrison
2020-04-07 15:45:22 -06:00
committed by Commit Bot
parent 7db1491a85
commit 9f6ff832d9

View File

@ -70,11 +70,15 @@ inline int64_t Int64MsToQ32x32(int64_t milliseconds) {
double result =
std::round(milliseconds * (NtpTime::kFractionsPerSecond / 1000.0));
if (result <= std::numeric_limits<int64_t>::min()) {
// Explicitly cast values to double to avoid implicit conversion warnings
// The conversion of the std::numeric_limits<int64_t>::max() triggers
// -Wimplicit-int-float-conversion warning in clang 10.0.0 without explicit
// cast
if (result <= static_cast<double>(std::numeric_limits<int64_t>::min())) {
return std::numeric_limits<int64_t>::min();
}
if (result >= std::numeric_limits<int64_t>::max()) {
if (result >= static_cast<double>(std::numeric_limits<int64_t>::max())) {
return std::numeric_limits<int64_t>::max();
}
@ -89,11 +93,15 @@ inline uint64_t Int64MsToUQ32x32(int64_t milliseconds) {
double result =
std::round(milliseconds * (NtpTime::kFractionsPerSecond / 1000.0));
if (result <= std::numeric_limits<uint64_t>::min()) {
// Explicitly cast values to double to avoid implicit conversion warnings
// The conversion of the std::numeric_limits<int64_t>::max() triggers
// -Wimplicit-int-float-conversion warning in clang 10.0.0 without explicit
// cast
if (result <= static_cast<double>(std::numeric_limits<uint64_t>::min())) {
return std::numeric_limits<uint64_t>::min();
}
if (result >= std::numeric_limits<uint64_t>::max()) {
if (result >= static_cast<double>(std::numeric_limits<uint64_t>::max())) {
return std::numeric_limits<uint64_t>::max();
}