Skip to content

Commit

Permalink
Merge bitcoin#24406: test: Fix Wambiguous-reversed-operator compiler …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fanquake committed Feb 23, 2022
2 parents b6a2670 + fafc4eb commit 16d05cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/test/fuzz/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class AddrManDeterministic : public AddrMan
* - 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);

Expand Down
12 changes: 6 additions & 6 deletions src/test/serialize_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class CSerializeMethodsTestSingle
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;
}
};

Expand Down

0 comments on commit 16d05cf

Please sign in to comment.