Skip to content

Commit cee1b27

Browse files
committed
Make sure binary operators are const to fix C++20
Fix errors of the form ../../src/system/tests/TestSystemPacketBuffer.cpp:1063:72: error: C++20 says that these are ambiguous, even though the second is reversed: [-Werror] 1063 | NL_TEST_ASSERT(inSuite, config_1.handle == original_handle_1); | ^~~~~~~~~~~~~~~~~ ../../third_party/nlunit-test/repo/src/nlunit-test.h:366:15: note: in definition of macro ‘NL_TEST_ASSERT’ 366 | if (!(inCondition)) \ | ^~~~~~~~~~~ ../../src/system/SystemPacketBuffer.h:690:10: note: candidate 1: ‘bool chip::System::PacketBufferHandle::operator==(const chip::System::PacketBufferHandle&)’ 690 | bool operator==(const PacketBufferHandle & aOther) { return mBuffer == aOther.mBuffer; } | ^~~~~~~~ ../../src/system/SystemPacketBuffer.h:690:10: note: candidate 2: ‘bool chip::System::PacketBufferHandle::operator==(const chip::System::PacketBufferHandle&)’ (reversed) ../../src/system/SystemPacketBuffer.h:690:10: note: try making the operator a ‘const’ member function when compiling with cpp_standard="gnu++20" by making sure comparators are const members.
1 parent 035d302 commit cee1b27

File tree

9 files changed

+24
-23
lines changed

9 files changed

+24
-23
lines changed

examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TargetVideoPlayerInfo
7272
public:
7373
TargetVideoPlayerInfo() {}
7474

75-
bool operator==(const TargetVideoPlayerInfo & other) { return this->mNodeId == other.mNodeId; }
75+
bool operator==(const TargetVideoPlayerInfo & other) const { return this->mNodeId == other.mNodeId; }
7676

7777
bool IsInitialized() { return mInitialized; }
7878
void Reset();

src/app/ConcreteAttributePath.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct ConcreteDataAttributePath : public ConcreteAttributePath
142142
ChipLogValueMEI(mClusterId), ChipLogValueMEI(mAttributeId));
143143
}
144144

145-
bool MatchesConcreteAttributePath(const ConcreteAttributePath & aOther) { return ConcreteAttributePath::operator==(aOther); }
145+
bool MatchesConcreteAttributePath(const ConcreteAttributePath & aOther) const { return ConcreteAttributePath::operator==(aOther); }
146146

147147
bool operator==(const ConcreteDataAttributePath & aOther) const
148148
{

src/app/clusters/bindings/PendingNotificationMap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class PendingNotificationMap
8888
return *this;
8989
}
9090

91-
bool operator!=(const Iterator & rhs) { return mIndex != rhs.mIndex; }
91+
bool operator!=(const Iterator & rhs) const { return mIndex != rhs.mIndex; }
9292

93-
bool operator==(const Iterator & rhs) { return mIndex == rhs.mIndex; }
93+
bool operator==(const Iterator & rhs) const { return mIndex == rhs.mIndex; }
9494

9595
private:
9696
PendingNotificationMap * mMap;

src/app/clusters/scenes-server/SceneTable.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SceneTable
149149

150150
bool IsValid() { return (mSceneId != kUndefinedSceneId); }
151151

152-
bool operator==(const SceneStorageId & other) { return (mGroupId == other.mGroupId && mSceneId == other.mSceneId); }
152+
bool operator==(const SceneStorageId & other) const { return (mGroupId == other.mGroupId && mSceneId == other.mSceneId); }
153153
};
154154

155155
/// @brief struct used to store data held in a scene
@@ -235,7 +235,7 @@ class SceneTable
235235
SceneTableEntry(SceneStorageId id) : mStorageId(id) {}
236236
SceneTableEntry(const SceneStorageId id, const SceneData data) : mStorageId(id), mStorageData(data) {}
237237

238-
bool operator==(const SceneTableEntry & other)
238+
bool operator==(const SceneTableEntry & other) const
239239
{
240240
return (mStorageId == other.mStorageId && mStorageData == other.mStorageData);
241241
}

src/credentials/FabricTable.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class ConstFabricIterator
298298
return GetCurrent();
299299
}
300300

301-
bool operator==(const ConstFabricIterator & other)
301+
bool operator==(const ConstFabricIterator & other) const
302302
{
303303
if (IsAtEnd())
304304
{
@@ -308,7 +308,7 @@ class ConstFabricIterator
308308
// Pending entry does not participate in finding this.
309309
return (mStart == other.mStart) && (mIndex == other.mIndex) && (mMaxSize == other.mMaxSize);
310310
}
311-
bool operator!=(const ConstFabricIterator & other) { return !(*this == other); }
311+
bool operator!=(const ConstFabricIterator & other) const { return !(*this == other); }
312312

313313
bool IsAtEnd() const { return (mIndex == mMaxSize); }
314314

src/credentials/GroupDataProvider.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class GroupDataProvider
7272
Platform::CopyString(name, groupName);
7373
}
7474
}
75-
bool operator==(const GroupInfo & other)
75+
bool operator==(const GroupInfo & other) const
7676
{
7777
return (this->group_id == other.group_id) && !strncmp(this->name, other.name, kGroupNameMax);
7878
}
@@ -151,7 +151,7 @@ class GroupDataProvider
151151
// Number of keys present
152152
uint8_t num_keys_used = 0;
153153

154-
bool operator==(const KeySet & other)
154+
bool operator==(const KeySet & other) const
155155
{
156156
VerifyOrReturnError(this->policy == other.policy && this->num_keys_used == other.num_keys_used, false);
157157
return !memcmp(this->epoch_keys, other.epoch_keys, this->num_keys_used * sizeof(EpochKey));

src/setup_payload/SetupPayload.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool PayloadContents::CheckPayloadCommonConstraints() const
146146
return true;
147147
}
148148

149-
bool PayloadContents::operator==(PayloadContents & input) const
149+
bool PayloadContents::operator==(const PayloadContents & input) const
150150
{
151151
return (this->version == input.version && this->vendorID == input.vendorID && this->productID == input.productID &&
152152
this->commissioningFlow == input.commissioningFlow && this->rendezvousInformation == input.rendezvousInformation &&
@@ -257,10 +257,11 @@ CHIP_ERROR SetupPayload::addOptionalExtensionData(const OptionalQRCodeInfoExtens
257257
return CHIP_NO_ERROR;
258258
}
259259

260-
CHIP_ERROR SetupPayload::getOptionalVendorData(uint8_t tag, OptionalQRCodeInfo & info)
260+
CHIP_ERROR SetupPayload::getOptionalVendorData(uint8_t tag, OptionalQRCodeInfo & info) const
261261
{
262-
VerifyOrReturnError(optionalVendorData.find(tag) != optionalVendorData.end(), CHIP_ERROR_KEY_NOT_FOUND);
263-
info = optionalVendorData[tag];
262+
const auto it = optionalVendorData.find(tag);
263+
VerifyOrReturnError(it != optionalVendorData.end(), CHIP_ERROR_KEY_NOT_FOUND);
264+
info = it->second;
264265

265266
return CHIP_NO_ERROR;
266267
}
@@ -273,7 +274,7 @@ CHIP_ERROR SetupPayload::getOptionalExtensionData(uint8_t tag, OptionalQRCodeInf
273274
return CHIP_NO_ERROR;
274275
}
275276

276-
optionalQRCodeInfoType SetupPayload::getNumericTypeFor(uint8_t tag)
277+
optionalQRCodeInfoType SetupPayload::getNumericTypeFor(uint8_t tag) const
277278
{
278279
optionalQRCodeInfoType elemType = optionalQRCodeInfoTypeUnknown;
279280

@@ -289,7 +290,7 @@ optionalQRCodeInfoType SetupPayload::getNumericTypeFor(uint8_t tag)
289290
return elemType;
290291
}
291292

292-
std::vector<OptionalQRCodeInfoExtension> SetupPayload::getAllOptionalExtensionData()
293+
std::vector<OptionalQRCodeInfoExtension> SetupPayload::getAllOptionalExtensionData() const
293294
{
294295
std::vector<OptionalQRCodeInfoExtension> returnedOptionalInfo;
295296
for (auto & entry : optionalExtensionData)
@@ -299,7 +300,7 @@ std::vector<OptionalQRCodeInfoExtension> SetupPayload::getAllOptionalExtensionDa
299300
return returnedOptionalInfo;
300301
}
301302

302-
bool SetupPayload::operator==(SetupPayload & input)
303+
bool SetupPayload::operator==(const SetupPayload & input) const
303304
{
304305
std::vector<OptionalQRCodeInfo> inputOptionalVendorData;
305306
std::vector<OptionalQRCodeInfoExtension> inputOptionalExtensionData;

src/setup_payload/SetupPayload.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct PayloadContents
130130

131131
bool isValidQRCodePayload() const;
132132
bool isValidManualCode() const;
133-
bool operator==(PayloadContents & input) const;
133+
bool operator==(const PayloadContents & input) const;
134134

135135
static bool IsValidSetupPIN(uint32_t setupPIN);
136136

@@ -233,7 +233,7 @@ class SetupPayload : public PayloadContents
233233
**/
234234
CHIP_ERROR removeSerialNumber();
235235

236-
bool operator==(SetupPayload & input);
236+
bool operator==(const SetupPayload & input) const;
237237

238238
private:
239239
std::map<uint8_t, OptionalQRCodeInfo> optionalVendorData;
@@ -267,14 +267,14 @@ class SetupPayload : public PayloadContents
267267
* @brief A function to retrieve the vector of CHIPQRCodeInfo infos
268268
* @return Returns a vector of CHIPQRCodeInfos
269269
**/
270-
std::vector<OptionalQRCodeInfoExtension> getAllOptionalExtensionData();
270+
std::vector<OptionalQRCodeInfoExtension> getAllOptionalExtensionData() const;
271271

272272
/** @brief A function to retrieve an optional QR Code info vendor object
273273
* @param tag 7 bit [0-127] tag number
274274
* @param info retrieved OptionalQRCodeInfo object
275275
* @return Returns a CHIP_ERROR_KEY_NOT_FOUND on error, CHIP_NO_ERROR otherwise
276276
**/
277-
CHIP_ERROR getOptionalVendorData(uint8_t tag, OptionalQRCodeInfo & info);
277+
CHIP_ERROR getOptionalVendorData(uint8_t tag, OptionalQRCodeInfo & info) const;
278278

279279
/** @brief A function to retrieve an optional QR Code info extended object
280280
* @param tag 8 bit [128-255] tag number
@@ -287,7 +287,7 @@ class SetupPayload : public PayloadContents
287287
* @param tag 8 bit [0-255] tag number
288288
* @return Returns an optionalQRCodeInfoType value
289289
**/
290-
optionalQRCodeInfoType getNumericTypeFor(uint8_t tag);
290+
optionalQRCodeInfoType getNumericTypeFor(uint8_t tag) const;
291291
};
292292

293293
} // namespace chip

src/system/SystemPacketBuffer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ class DLL_EXPORT PacketBufferHandle
687687

688688
PacketBuffer * Get() const { return mBuffer; }
689689

690-
bool operator==(const PacketBufferHandle & aOther) { return mBuffer == aOther.mBuffer; }
690+
bool operator==(const PacketBufferHandle & aOther) const { return mBuffer == aOther.mBuffer; }
691691

692692
#if CHIP_SYSTEM_PACKETBUFFER_HAS_RIGHTSIZE
693693
void InternalRightSize();

0 commit comments

Comments
 (0)