Skip to content

Commit ccd8da9

Browse files
Fix compile error on older g++ (#34630)
- 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).
1 parent 3263e40 commit ccd8da9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

examples/all-clusters-app/all-clusters-common/include/WhmDelegate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class WaterHeaterManagementDelegate : public WaterHeaterManagement::Delegate
167167
* @param percentageReplaced The % of water being replaced with water with a temperature of replacedWaterTemperature.
168168
* @param replacedWaterTemperature The temperature of the percentageReplaced water.
169169
*/
170-
void DrawOffHotWater(uint8_t percentageReplaced, uint16_t replacedWaterTemperature);
170+
void DrawOffHotWater(chip::Percent percentageReplaced, uint16_t replacedWaterTemperature);
171171

172172
private:
173173
/**

examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void WaterHeaterManagementDelegate::SetTargetWaterTemperature(uint16_t targetWat
294294
CheckIfHeatNeedsToBeTurnedOnOrOff();
295295
}
296296

297-
void WaterHeaterManagementDelegate::DrawOffHotWater(uint8_t percentageReplaced, uint16_t replacedWaterTemperature)
297+
void WaterHeaterManagementDelegate::DrawOffHotWater(Percent percentageReplaced, uint16_t replacedWaterTemperature)
298298
{
299299
// Only supported in the kTankPercent is supported.
300300
// Replaces percentageReplaced% of the water in the tank with water of a temperature replacedWaterTemperature
@@ -303,7 +303,7 @@ void WaterHeaterManagementDelegate::DrawOffHotWater(uint8_t percentageReplaced,
303303
// See if all of the water has now been replaced with replacedWaterTemperature
304304
if (mTankPercentage >= percentageReplaced)
305305
{
306-
mTankPercentage -= percentageReplaced;
306+
mTankPercentage = static_cast<Percent>(mTankPercentage - percentageReplaced);
307307
}
308308
else
309309
{

0 commit comments

Comments
 (0)