Merge bitcoin/bitcoin#24406: test: Fix Wambiguous-reversed-operator compiler warnings

fafc4eb363 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 fafc4eb363, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: 92cd62ae06ee1393a6dc2ea6f3f553595a8f8d66f51592d231b42122bfb71ed4801a016daafc85360040339c5ae59b76888265cec37449c4688d6c7768f4567e
This commit is contained in:
fanquake 2022-02-23 11:06:36 +00:00
commit 16d05cf6b9
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
2 changed files with 7 additions and 7 deletions

View File

@ -137,7 +137,7 @@ public:
* - vvNew entries refer to the same addresses
* - vvTried entries refer to the same addresses
*/
bool operator==(const AddrManDeterministic& other)
bool operator==(const AddrManDeterministic& other) const
{
LOCK2(m_impl->cs, other.m_impl->cs);

View File

@ -38,13 +38,13 @@ public:
READWRITE(obj.txval);
}
bool operator==(const CSerializeMethodsTestSingle& rhs)
bool operator==(const CSerializeMethodsTestSingle& rhs) const
{
return intval == rhs.intval && \
boolval == rhs.boolval && \
stringval == rhs.stringval && \
strcmp(charstrval, rhs.charstrval) == 0 && \
*txval == *rhs.txval;
return intval == rhs.intval &&
boolval == rhs.boolval &&
stringval == rhs.stringval &&
strcmp(charstrval, rhs.charstrval) == 0 &&
*txval == *rhs.txval;
}
};