Skip to content

Commit 16d05cf

Browse files
committed
Merge bitcoin/bitcoin#24406: test: Fix Wambiguous-reversed-operator compiler warnings
fafc4eb test: Fix Wambiguous-reversed-operator compiler warnings (MarcoFalke) Pull request description: Add a missing const to avoid the C++20 clang **compiler warning**: ``` test/fuzz/addrman.cpp:325:22: error: ISO C++20 considers use of overloaded operator '==' (with operand types 'AddrManDeterministic' and 'AddrManDeterministic') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator] assert(addr_man1 == addr_man2); ~~~~~~~~~ ^ ~~~~~~~~~ /usr/include/assert.h:93:27: note: expanded from macro 'assert' (static_cast <bool> (expr) \ ^~~~ test/fuzz/addrman.cpp:140:10: note: ambiguity is between a regular call to this operator and a call with the argument order reversed bool operator==(const AddrManDeterministic& other) ^ 1 error generated. ``` This patch also fixes the **compile error** if the first operand is `const`: ``` test/fuzz/addrman.cpp:326:23: error: invalid operands to binary expression ('const AddrManDeterministic' and 'AddrManDeterministic') assert(addr_man_1 == addr_man2); ~~~~~~~~~~ ^ ~~~~~~~~~ /usr/include/assert.h:90:27: note: expanded from macro 'assert' (static_cast <bool> (expr) \ ^~~~ test/fuzz/addrman.cpp:140:10: note: candidate function not viable: 'this' argument has type 'const AddrManDeterministic', but method is not marked const bool operator==(const AddrManDeterministic& other) ^ 1 error generated. ACKs for top commit: hebasto: ACK fafc4eb, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 92cd62ae06ee1393a6dc2ea6f3f553595a8f8d66f51592d231b42122bfb71ed4801a016daafc85360040339c5ae59b76888265cec37449c4688d6c7768f4567e
2 parents b6a2670 + fafc4eb commit 16d05cf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/test/fuzz/addrman.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class AddrManDeterministic : public AddrMan
137137
* - vvNew entries refer to the same addresses
138138
* - vvTried entries refer to the same addresses
139139
*/
140-
bool operator==(const AddrManDeterministic& other)
140+
bool operator==(const AddrManDeterministic& other) const
141141
{
142142
LOCK2(m_impl->cs, other.m_impl->cs);
143143

src/test/serialize_tests.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ class CSerializeMethodsTestSingle
3838
READWRITE(obj.txval);
3939
}
4040

41-
bool operator==(const CSerializeMethodsTestSingle& rhs)
41+
bool operator==(const CSerializeMethodsTestSingle& rhs) const
4242
{
43-
return intval == rhs.intval && \
44-
boolval == rhs.boolval && \
45-
stringval == rhs.stringval && \
46-
strcmp(charstrval, rhs.charstrval) == 0 && \
47-
*txval == *rhs.txval;
43+
return intval == rhs.intval &&
44+
boolval == rhs.boolval &&
45+
stringval == rhs.stringval &&
46+
strcmp(charstrval, rhs.charstrval) == 0 &&
47+
*txval == *rhs.txval;
4848
}
4949
};
5050

0 commit comments

Comments
 (0)