Merge bitcoin/bitcoin#35120: btcsignals: delete broken scoped_connection move assignment

b83a999b14 btcsignals: delete broken scoped_connection move assignment (Thomas)

Pull request description:

  The defaulted move-assignment operator for `scoped_connection` overwrites `m_conn` without first calling `disconnect()`. Since disconnection is signaled via the liveness flag (which is never cleared) the old callback remains registered in the signal and keeps firing, violating the RAII contract:

  ```cpp
  int val{0};
  btcsignals::scoped_connection sc0 = sig.connect(IncrementCallback);
  btcsignals::scoped_connection sc1 = sig.connect(SquareCallback);
  sc0 = std::move(sc1);
  val = 3; sig(val);
  // Expected: 9 (only SquareCallback)
  // Actual:  16 (both callbacks fire, old connection leaked)
  ```

  Move assignment is unused in the codebase, so following the review discussion this deletes the broken operator instead of fixing it. A correct implementation can be added if a use case arises.

  Earlier versions of this PR fixed the operator and added a default constructor to enable the member-variable assignment pattern; that was dropped in favor of removing the unused operation.

ACKs for top commit:
  maflcko:
    lgtm ACK b83a999b14
  sedited:
    ACK b83a999b14

Tree-SHA512: 794347e9cb868d50957ea298f7df6eac5b9f55b9d35ab09e41be269923c45e0709194431dea66b7977c74f802150ba53cb2d12d35937f4966ec302bffb9c95f8
This commit is contained in:
merge-script
2026-06-11 13:35:40 +02:00

View File

@@ -123,11 +123,11 @@ public:
scoped_connection(connection rhs) noexcept : m_conn{std::move(rhs)} {}
scoped_connection(scoped_connection&&) noexcept = default;
scoped_connection& operator=(scoped_connection&&) noexcept = default;
/**
* For simplicity, disable copy assignment and construction.
* For simplicity, disable copy construction and copy/move assignment.
*/
scoped_connection& operator=(scoped_connection&&) = delete;
scoped_connection& operator=(const scoped_connection&) = delete;
scoped_connection(const scoped_connection&) = delete;