From 9f6ff832d99ae697de34640b0d348983d908604c Mon Sep 17 00:00:00 2001 From: mmorrison Date: Tue, 7 Apr 2020 15:45:22 -0600 Subject: [PATCH] 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 Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#31041} --- system_wrappers/include/ntp_time.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/system_wrappers/include/ntp_time.h b/system_wrappers/include/ntp_time.h index 1f57558b71..332f8f4624 100644 --- a/system_wrappers/include/ntp_time.h +++ b/system_wrappers/include/ntp_time.h @@ -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::min()) { + // Explicitly cast values to double to avoid implicit conversion warnings + // The conversion of the std::numeric_limits::max() triggers + // -Wimplicit-int-float-conversion warning in clang 10.0.0 without explicit + // cast + if (result <= static_cast(std::numeric_limits::min())) { return std::numeric_limits::min(); } - if (result >= std::numeric_limits::max()) { + if (result >= static_cast(std::numeric_limits::max())) { return std::numeric_limits::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::min()) { + // Explicitly cast values to double to avoid implicit conversion warnings + // The conversion of the std::numeric_limits::max() triggers + // -Wimplicit-int-float-conversion warning in clang 10.0.0 without explicit + // cast + if (result <= static_cast(std::numeric_limits::min())) { return std::numeric_limits::min(); } - if (result >= std::numeric_limits::max()) { + if (result >= static_cast(std::numeric_limits::max())) { return std::numeric_limits::max(); }