Repository: bitcoin/bitcoin
File: src/script/script.h (C/C++)

Code before:
        if (vch.size() > nMaxNumSize) {
            throw scriptnum_error("script number overflow");
        }
        if (fRequireMinimal && vch.size() > 0) {
            // Check that the number is encoded with the minimum possible
            // number of bytes.
            //
            // If the most-significant-byte - excluding the sign bit - is zero
            // then we're not minimal. Note how this test also rejects the
            // negative-zero encoding, 0x80.
            if ((vch.back() & 0x7f) == 0) {
                // One exception: if there's more than one byte and the most
                // significant bit of the second-most-significant-byte is set
                // it would conflict with the sign bit. An example of this case
                // is +-255, which encode to 0xff00 and 0xff80 respectively.
                // (big-endian).
                if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
                    throw scriptnum_error("non-minimally encoded script number");
                }
            }
        }
        m_value = set_vch(vch);
    }

    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); }
    inline bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }

    inline CScriptNum operator+(   const int64_t& rhs)    const { return CScriptNum(m_value + rhs);}
    inline CScriptNum operator-(   const int64_t& rhs)    const { return CScriptNum(m_value - rhs);}
    inline CScriptNum operator+(   const CScriptNum& rhs) const { return operator+(rhs.m_value);   }
    inline CScriptNum operator-(   const CScriptNum& rhs) const { return operator-(rhs.m_value);   }

    inline CScriptNum& operator+=( const CScriptNum& rhs)       { return operator+=(rhs.m_value);  }
    inline CScriptNum& operator-=( const CScriptNum& rhs)       { return operator-=(rhs.m_value);  }

    inline CScriptNum operator&(   const int64_t& rhs)    const { return CScriptNum(m_value & rhs);}
    inline CScriptNum operator&(   const CScriptNum& rhs) const { return operator&(rhs.m_value);   }

    inline CScriptNum& operator&=( const CScriptNum& rhs)       { return operator&=(rhs.m_value);  }


Review comment (suggestion):
nit (here and for all other new `operator<=>`): perhaps better to be explicit about the `std::strong_ordering` return type? And perhaps making it `constexpr` while touching?

<details>
<summary>git diff on 48840bfc2d</summary>

```diff
diff --git a/src/prevector.h b/src/prevector.h
index d4d90c7350..595be4a603 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -7,6 +7,7 @@
 
 #include <algorithm>
 #include <cassert>
+#include <compare>
 #include <cstddef>
 #include <cstdint>
 #include <cstdlib>
@@ -71,8 +72,8 @@ public:
         iterator& operator+=(size_type n) { ptr += n; return *this; }
         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; }
-        auto operator<=>(iterator x) const { return ptr <=> x.ptr; }
+        constexpr bool operator==(iterator x) const { return ptr == x.ptr; }
+        constexpr std::strong_ordering operator<=>(iterator x) const { return ptr <=> x.ptr; }
     };
 
     class const_iterator {
@@ -99,8 +100,8 @@ public:
         const_iterator& operator+=(size_type n) { ptr += n; return *this; }
         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; }
-        auto operator<=>(const_iterator x) const { return ptr <=> x.ptr; }
+        constexpr bool operator==(const_iterator x) const { return ptr == x.ptr; }
+        constexpr std::strong_ordering operator<=>(const_iterator x) const { return ptr <=> x.ptr; }
     };
 
 private:
diff --git a/src/script/script.h b/src/script/script.h
index b06be9c975..f1472a7dd3 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -14,6 +14,7 @@
 #include <util/hash_type.h>
 
 #include <cassert>
+#include <compare>
 #include <cstdint>
 #include <cstring>
 #include <limits>
@@ -269,11 +270,11 @@ public:
         m_value = set_vch(vch);
     }
 
-    inline bool operator==(const int64_t& rhs) const    { return m_value == rhs; }
-    inline auto operator<=>(const int64_t& rhs) const    { return m_value <=> rhs; }
+    inline constexpr bool operator==(const int64_t& rhs) const    { return m_value == rhs; }
+    inline constexpr std::strong_ordering operator<=>(const int64_t& rhs) const    { return m_value <=> rhs; }
 
-    inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
-    inline auto operator<=>(const CScriptNum& rhs) const { return operator<=>(rhs.m_value); }
+    inline constexpr bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
+    inline constexpr std::strong_ordering operator<=>(const CScriptNum& rhs) const { return operator<=>(rhs.m_value); }
 
     inline CScriptNum operator+(   const int64_t& rhs)    const { return CScriptNum(m_value + rhs);}
     inline CScriptNum operator-(   const int64_t& rhs)    const { return CScriptNum(m_value - rhs);}
diff --git a/src/test/scriptnum10.h b/src/test/scriptnum10.h
index 402606714d..fd112d6ff7 100644
--- a/src/test/scriptnum10.h
+++ b/src/test/scriptnum10.h
@@ -7,6 +7,7 @@
 #define BITCOIN_TEST_SCRIPTNUM10_H
 
 #include <cassert>
+#include <compare>
 #include <cstdint>
 #include <limits>
 #include <stdexcept>
@@ -60,11 +61,11 @@ public:
         m_value = set_vch(vch);
     }
 
-    inline bool operator==(const int64_t& rhs) const    { return m_value == rhs; }
-    inline auto operator<=>(const int64_t& rhs) const    { return m_value <=> rhs; }
+    inline constexpr bool operator==(const int64_t& rhs) const    { return m_value == rhs; }
+    inline constexpr std::strong_ordering operator<=>(const int64_t& rhs) const    { return m_value <=> rhs; }
 
-    inline bool operator==(const CScriptNum10& rhs) const { return operator==(rhs.m_value); }
-    inline auto operator<=>(const CScriptNum10& rhs) const { return operator<=>(rhs.m_value); }
+    inline constexpr bool operator==(const CScriptNum10& rhs) const { return operator==(rhs.m_value); }
+    inline constexpr std::strong_ordering operator<=>(const CScriptNum10& rhs) const { return operator<=>(rhs.m_value); }
 
     inline CScriptNum10 operator+(   const int64_t& rhs)    const { return CScriptNum10(m_value + rhs);}
     inline CScriptNum10 operator-(   const int64_t& rhs)    const { return CScriptNum10(m_value - rhs);}
diff --git a/src/util/bitdeque.h b/src/util/bitdeque.h
index 21934e02da..be3e0fd859 100644
--- a/src/util/bitdeque.h
+++ b/src/util/bitdeque.h
@@ -6,6 +6,7 @@
 #define BITCOIN_UTIL_BITDEQUE_H
 
 #include <bitset>
+#include <compare>
 #include <cstddef>
 #include <deque>
 #include <limits>
@@ -99,8 +100,8 @@ class bitdeque
         friend Iterator operator+(Iterator x, difference_type dist) { x += dist; return x; }
         friend Iterator operator+(difference_type dist, Iterator x) { x += dist; return x; }
         friend Iterator operator-(Iterator x, difference_type dist) { x -= dist; return x; }
-        friend auto 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 constexpr std::strong_ordering 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 constexpr 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); }
     };

```
</details>


Code after:
        if (vch.size() > nMaxNumSize) {
            throw scriptnum_error("script number overflow");
        }
        if (fRequireMinimal && vch.size() > 0) {
            // Check that the number is encoded with the minimum possible
            // number of bytes.
            //
            // If the most-significant-byte - excluding the sign bit - is zero
            // then we're not minimal. Note how this test also rejects the
            // negative-zero encoding, 0x80.
            if ((vch.back() & 0x7f) == 0) {
                // One exception: if there's more than one byte and the most
                // significant bit of the second-most-significant-byte is set
                // it would conflict with the sign bit. An example of this case
                // is +-255, which encode to 0xff00 and 0xff80 respectively.
                // (big-endian).
                if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
                    throw scriptnum_error("non-minimally encoded script number");
                }
            }
        }
        m_value = set_vch(vch);
    }

    inline bool operator==(const int64_t& rhs) const    { return m_value == rhs; }
    inline auto operator<=>(const int64_t& rhs) const    { return m_value <=> rhs; }

    inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
    inline auto operator<=>(const CScriptNum& rhs) const { return operator<=>(rhs.m_value); }

    inline CScriptNum operator+(   const int64_t& rhs)    const { return CScriptNum(m_value + rhs);}
    inline CScriptNum operator-(   const int64_t& rhs)    const { return CScriptNum(m_value - rhs);}
    inline CScriptNum operator+(   const CScriptNum& rhs) const { return operator+(rhs.m_value);   }
    inline CScriptNum operator-(   const CScriptNum& rhs) const { return operator-(rhs.m_value);   }

    inline CScriptNum& operator+=( const CScriptNum& rhs)       { return operator+=(rhs.m_value);  }
    inline CScriptNum& operator-=( const CScriptNum& rhs)       { return operator-=(rhs.m_value);  }

    inline CScriptNum operator&(   const int64_t& rhs)    const { return CScriptNum(m_value & rhs);}
    inline CScriptNum operator&(   const CScriptNum& rhs) const { return operator&(rhs.m_value);   }

    inline CScriptNum& operator&=( const CScriptNum& rhs)       { return operator&=(rhs.m_value);  }

    inline CScriptNum operator-()                         const
    {
        assert(m_value != std::numeric_limits<int64_t>::min());
        return CScriptNum(-m_value);
    }

    inline CScriptNum& operator=( const int64_t& rhs)
    {