From ccd8da9764597a1f48f712c8eb0098f1d3c51b6e Mon Sep 17 00:00:00 2001 From: Tennessee Carmel-Veilleux Date: Tue, 30 Jul 2024 15:26:09 -0400 Subject: [PATCH] Fix compile error on older g++ (#34630) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Older g++ in Ubuntu 20.04LTS seems to have issues with invalidly doing integer promotion in some cases where it otherwise should not happen. This broke for some developers with: ``` ../../third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp: In member function ‘void chip::app::Clusters::WaterHeaterManagement::WaterHeaterManagementDelegate::DrawOffHotWater(chip::Percent, uint16_t)’: ../../third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp:306:29: error: conversion from ‘int’ to ‘chip::Percent’ {aka ‘unsigned char’} may change value [-Werror=conversion] 306 | mTankPercentage -= percentageReplaced; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ At global scope: cc1plus: error: unrecognized command line option ‘-Wno-unknown-warning-option’ [-Werror] cc1plus: all warnings being treated as errors [17/171] c++ obj/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/src/chip-all-clusters-common.device-energy-management-mode.cpp.o ninja: build stopped: subcommand failed. ``` - This PR fixes the issue (validated with one such user). --- .../all-clusters-common/include/WhmDelegate.h | 2 +- .../all-clusters-common/src/WhmDelegateImpl.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/WhmDelegate.h b/examples/all-clusters-app/all-clusters-common/include/WhmDelegate.h index ecabfe22792f25..ad73239e77990d 100644 --- a/examples/all-clusters-app/all-clusters-common/include/WhmDelegate.h +++ b/examples/all-clusters-app/all-clusters-common/include/WhmDelegate.h @@ -167,7 +167,7 @@ class WaterHeaterManagementDelegate : public WaterHeaterManagement::Delegate * @param percentageReplaced The % of water being replaced with water with a temperature of replacedWaterTemperature. * @param replacedWaterTemperature The temperature of the percentageReplaced water. */ - void DrawOffHotWater(uint8_t percentageReplaced, uint16_t replacedWaterTemperature); + void DrawOffHotWater(chip::Percent percentageReplaced, uint16_t replacedWaterTemperature); private: /** diff --git a/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp b/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp index fd19a3c59d740b..0568e5c9c7d002 100644 --- a/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp @@ -294,7 +294,7 @@ void WaterHeaterManagementDelegate::SetTargetWaterTemperature(uint16_t targetWat CheckIfHeatNeedsToBeTurnedOnOrOff(); } -void WaterHeaterManagementDelegate::DrawOffHotWater(uint8_t percentageReplaced, uint16_t replacedWaterTemperature) +void WaterHeaterManagementDelegate::DrawOffHotWater(Percent percentageReplaced, uint16_t replacedWaterTemperature) { // Only supported in the kTankPercent is supported. // Replaces percentageReplaced% of the water in the tank with water of a temperature replacedWaterTemperature @@ -303,7 +303,7 @@ void WaterHeaterManagementDelegate::DrawOffHotWater(uint8_t percentageReplaced, // See if all of the water has now been replaced with replacedWaterTemperature if (mTankPercentage >= percentageReplaced) { - mTankPercentage -= percentageReplaced; + mTankPercentage = static_cast(mTankPercentage - percentageReplaced); } else {