refactor: Remove all `operator!=` definitions
What changed, and why it matters
This commit is a routine code cleanup: it removes hand-written 'not equal' comparison operators across many files because modern C++ compilers can automatically generate them from the existing 'equal' operators. There is no functional change and no security risk.
No action required; this is a safe refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deletes explicit operator!= definitions for multiple classes and iterators (FlatFilePos, CNetAddr, CSubNet, CService, prevector iterators/container, COutPoint, CTxIn, CTxOut, CTransaction, transaction identifiers, CPubKey variants, CScriptNum, allocator types, uint256/base_blob, bitdeque iterator, BaseHash). In C++20, the compiler synthesizes operator!= from operator== via the rewritten expression rules, so these removals are behavior-preserving refactoring. No logic, parsing, serialization, or consensus code is altered.
Changed components
src/flatfile.hsrc/netaddress.hsrc/prevector.hsrc/primitives/transaction.hsrc/primitives/transaction_identifier.hsrc/pubkey.hsrc/script/script.hsrc/support/allocators/pool.hsrc/support/allocators/secure.hsrc/support/allocators/zeroafterfree.hsrc/test/scriptnum10.hsrc/uint256.hsrc/util/bitdeque.hsrc/util/hash_type.hInspect captured patch +0 / −78
diff --git a/src/flatfile.h b/src/flatfile.h
index 3edb0b85..94ee9062 100644
--- a/src/flatfile.h
+++ b/src/flatfile.h
@@ -29,10 +29,6 @@ struct FlatFilePos
return (a.nFile == b.nFile && a.nPos == b.nPos);
}
- friend bool operator!=(const FlatFilePos &a, const FlatFilePos &b) {
- return !(a == b);
- }
-
bool IsNull() const { return (nFile == -1); }
std::string ToString() const;
diff --git a/src/netaddress.h b/src/netaddress.h
index 48dbf03a..c6556809 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -210,7 +210,6 @@ public:
bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
friend bool operator==(const CNetAddr& a, const CNetAddr& b);
- friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
friend bool operator<(const CNetAddr& a, const CNetAddr& b);
/**
@@ -523,7 +522,6 @@ public:
bool IsValid() const;
friend bool operator==(const CSubNet& a, const CSubNet& b);
- friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
friend bool operator<(const CSubNet& a, const CSubNet& b);
};
@@ -554,7 +552,6 @@ public:
*/
[[nodiscard]] sa_family_t GetSAFamily() const;
friend bool operator==(const CService& a, const CService& b);
- friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
friend bool operator<(const CService& a, const CService& b);
std::vector<unsigned char> GetKey() const;
std::string ToStringAddrPort() const;
diff --git a/src/prevector.h b/src/prevector.h
index fb7d52f4..2c794d71 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -72,7 +72,6 @@ public:
iterator operator-(size_type n) const { return iterator(ptr - n); }
iterator& operator-=(size_type n) { ptr -= n; return *this; }
bool operator==(iterator x) const { return ptr == x.ptr; }
- bool operator!=(iterator x) const { return ptr != x.ptr; }
bool operator>=(iterator x) const { return ptr >= x.ptr; }
bool operator<=(iterator x) const { return ptr <= x.ptr; }
bool operator>(iterator x) const { return ptr > x.ptr; }
@@ -104,7 +103,6 @@ public:
const_iterator operator-(size_type n) const { return const_iterator(ptr - n); }
const_iterator& operator-=(size_type n) { ptr -= n; return *this; }
bool operator==(const_iterator x) const { return ptr == x.ptr; }
- bool operator!=(const_iterator x) const { return ptr != x.ptr; }
bool operator>=(const_iterator x) const { return ptr >= x.ptr; }
bool operator<=(const_iterator x) const { return ptr <= x.ptr; }
bool operator>(const_iterator x) const { return ptr > x.ptr; }
@@ -451,10 +449,6 @@ public:
return true;
}
- bool operator!=(const prevector<N, T, Size, Diff>& other) const {
- return !(*this == other);
- }
-
bool operator<(const prevector<N, T, Size, Diff>& other) const {
if (size() < other.size()) {
return true;
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
index 295bce61..da3db602 100644
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -51,11 +51,6 @@ public:
return (a.hash == b.hash && a.n == b.n);
}
- friend bool operator!=(const COutPoint& a, const COutPoint& b)
- {
- return !(a == b);
- }
-
std::string ToString() const;
};
@@ -135,11 +130,6 @@ public:
a.nSequence == b.nSequence);
}
- friend bool operator!=(const CTxIn& a, const CTxIn& b)
- {
- return !(a == b);
- }
-
std::string ToString() const;
};
@@ -178,11 +168,6 @@ public:
a.scriptPubKey == b.scriptPubKey);
}
- friend bool operator!=(const CTxOut& a, const CTxOut& b)
- {
- return !(a == b);
- }
-
std::string ToString() const;
};
@@ -363,11 +348,6 @@ public:
return a.GetWitnessHash() == b.GetWitnessHash();
}
- friend bool operator!=(const CTransaction& a, const CTransaction& b)
- {
- return !operator==(a, b);
- }
-
std::string ToString() const;
bool HasWitness() const { return m_has_witness; }
diff --git a/src/primitives/transaction_identifier.h b/src/primitives/transaction_identifier.h
index b753c1df..79af2dde 100644
--- a/src/primitives/transaction_identifier.h
+++ b/src/primitives/transaction_identifier.h
@@ -38,8 +38,6 @@ public:
template <typename Other>
bool operator==(const Other& other) const { return Compare(other) == 0; }
template <typename Other>
- bool operator!=(const Other& other) const { return Compare(other) != 0; }
- template <typename Other>
bool operator<(const Other& other) const { return Compare(other) < 0; }
const uint256& ToUint256() const LIFETIMEBOUND { return m_wrapped; }
diff --git a/src/pubkey.h b/src/pubkey.h
index 5ae7f75d..02ad7371 100644
--- a/src/pubkey.h
+++ b/src/pubkey.h
@@ -121,10 +121,6 @@ public:
return a.vch[0] == b.vch[0] &&
memcmp(a.vch, b.vch, a.size()) == 0;
}
- friend bool operator!=(const CPubKey& a, const CPubKey& b)
- {
- return !(a == b);
- }
friend bool operator<(const CPubKey& a, const CPubKey& b)
{
return a.vch[0] < b.vch[0] ||
@@ -302,7 +298,6 @@ public:
unsigned char* begin() { return m_keydata.begin(); }
unsigned char* end() { return m_keydata.end(); }
bool operator==(const XOnlyPubKey& other) const { return m_keydata == other.m_keydata; }
- bool operator!=(const XOnlyPubKey& other) const { return m_keydata != other.m_keydata; }
bool operator<(const XOnlyPubKey& other) const { return m_keydata < other.m_keydata; }
//! Implement serialization without length prefixes since it is a fixed length
@@ -336,11 +331,6 @@ public:
{
return a.m_pubkey == b.m_pubkey;
}
-
- bool friend operator!=(const EllSwiftPubKey& a, const EllSwiftPubKey& b)
- {
- return a.m_pubkey != b.m_pubkey;
- }
};
struct CExtPubKey {
@@ -360,11 +350,6 @@ struct CExtPubKey {
a.pubkey == b.pubkey;
}
- friend bool operator!=(const CExtPubKey &a, const CExtPubKey &b)
- {
- return !(a == b);
- }
-
friend bool operator<(const CExtPubKey &a, const CExtPubKey &b)
{
if (a.pubkey < b.pubkey) {
diff --git a/src/script/script.h b/src/script/script.h
index b556aae6..633b5609 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -270,14 +270,12 @@ public:
}
inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
- inline bool operator!=(const int64_t& rhs) const { return m_value != rhs; }
inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
- inline bool operator!=(const CScriptNum& rhs) const { return operator!=(rhs.m_value); }
inline bool operator<=(const CScriptNum& rhs) const { return operator<=(rhs.m_value); }
inline bool operator< (const CScriptNum& rhs) const { return operator< (rhs.m_value); }
inline bool operator>=(const CScriptNum& rhs) const { return operator>=(rhs.m_value); }
diff --git a/src/support/allocators/pool.h b/src/support/allocators/pool.h
index 86b5da5a..108f0938 100644
--- a/src/support/allocators/pool.h
+++ b/src/support/allocators/pool.h
@@ -352,11 +352,4 @@ bool operator==(const PoolAllocator<T1, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& a,
return a.resource() == b.resource();
}
-template <class T1, class T2, std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES>
-bool operator!=(const PoolAllocator<T1, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& a,
- const PoolAllocator<T2, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& b) noexcept
-{
- return !(a == b);
-}
-
#endif // BITCOIN_SUPPORT_ALLOCATORS_POOL_H
diff --git a/src/support/allocators/secure.h b/src/support/allocators/secure.h
index e7ffc9e2..8285b306 100644
--- a/src/support/allocators/secure.h
+++ b/src/support/allocators/secure.h
@@ -46,11 +46,6 @@ struct secure_allocator {
{
return true;
}
- template <typename U>
- friend bool operator!=(const secure_allocator&, const secure_allocator<U>&) noexcept
- {
- return false;
- }
};
// This is exactly like std::string, but with a custom allocator.
diff --git a/src/support/allocators/zeroafterfree.h b/src/support/allocators/zeroafterfree.h
index 6d50eb70..9a942a41 100644
--- a/src/support/allocators/zeroafterfree.h
+++ b/src/support/allocators/zeroafterfree.h
@@ -38,11 +38,6 @@ struct zero_after_free_allocator {
{
return true;
}
- template <typename U>
- friend bool operator!=(const zero_after_free_allocator&, const zero_after_free_allocator<U>&) noexcept
- {
- return false;
- }
};
/** Byte-vector that clears its contents before deletion. */
diff --git a/src/test/scriptnum10.h b/src/test/scriptnum10.h
index db66f3a1..bf708aac 100644
--- a/src/test/scriptnum10.h
+++ b/src/test/scriptnum10.h
@@ -61,14 +61,12 @@ public:
}
inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
- inline bool operator!=(const int64_t& rhs) const { return m_value != rhs; }
inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
inline bool operator==(const CScriptNum10& rhs) const { return operator==(rhs.m_value); }
- inline bool operator!=(const CScriptNum10& rhs) const { return operator!=(rhs.m_value); }
inline bool operator<=(const CScriptNum10& rhs) const { return operator<=(rhs.m_value); }
inline bool operator< (const CScriptNum10& rhs) const { return operator< (rhs.m_value); }
inline bool operator>=(const CScriptNum10& rhs) const { return operator>=(rhs.m_value); }
diff --git a/src/uint256.h b/src/uint256.h
index 85c030dc..d4204275 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -64,7 +64,6 @@ public:
constexpr int Compare(const base_blob& other) const { return std::memcmp(m_data.data(), other.m_data.data(), WIDTH); }
friend constexpr bool operator==(const base_blob& a, const base_blob& b) { return a.Compare(b) == 0; }
- friend constexpr bool operator!=(const base_blob& a, const base_blob& b) { return a.Compare(b) != 0; }
friend constexpr bool operator<(const base_blob& a, const base_blob& b) { return a.Compare(b) < 0; }
/** @name Hex representation
diff --git a/src/util/bitdeque.h b/src/util/bitdeque.h
index ac9d3024..2d21c8b3 100644
--- a/src/util/bitdeque.h
+++ b/src/util/bitdeque.h
@@ -104,7 +104,6 @@ class bitdeque
friend bool operator<=(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) <= std::tie(y.m_it, y.m_bitpos); }
friend bool operator>=(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) >= std::tie(y.m_it, y.m_bitpos); }
friend bool operator==(const Iterator& x, const Iterator& y) { return x.m_it == y.m_it && x.m_bitpos == y.m_bitpos; }
- friend bool operator!=(const Iterator& x, const Iterator& y) { return x.m_it != y.m_it || x.m_bitpos != y.m_bitpos; }
reference operator*() const { return (*m_it)[m_bitpos]; }
reference operator[](difference_type pos) const { return *(*this + pos); }
};
diff --git a/src/util/hash_type.h b/src/util/hash_type.h
index 13b831cf..5b4f93b8 100644
--- a/src/util/hash_type.h
+++ b/src/util/hash_type.h
@@ -50,11 +50,6 @@ public:
return m_hash == other.m_hash;
}
- bool operator!=(const BaseHash<HashType>& other) const noexcept
- {
- return !(m_hash == other.m_hash);
- }
-
bool operator<(const BaseHash<HashType>& other) const noexcept
{
return m_hash < other.m_hash;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.