From 5bb35e68fe6f5b586499f0b5a3517abe0ef54c81 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Wed, 3 Jun 2026 13:41:36 +0100 Subject: [PATCH 1/4] Use `constexpr` whenever possible These have a guaranteed compile time evaluation and may be used in constant expressions themselves. --- src/crypto/hmac_sha256.h | 2 +- src/crypto/hmac_sha512.h | 2 +- src/crypto/ripemd160.h | 2 +- src/crypto/sha1.h | 2 +- src/crypto/sha256.h | 2 +- src/support/lockedpool.h | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/crypto/hmac_sha256.h b/src/crypto/hmac_sha256.h index a26947d5e0af..c81a268adba7 100644 --- a/src/crypto/hmac_sha256.h +++ b/src/crypto/hmac_sha256.h @@ -17,7 +17,7 @@ class CHMAC_SHA256 CSHA256 inner; public: - static const size_t OUTPUT_SIZE = 32; + static constexpr size_t OUTPUT_SIZE = 32; CHMAC_SHA256(const unsigned char* key, size_t keylen); CHMAC_SHA256& Write(const unsigned char* data, size_t len) diff --git a/src/crypto/hmac_sha512.h b/src/crypto/hmac_sha512.h index dfae8d05e5ab..75c3d91c0a91 100644 --- a/src/crypto/hmac_sha512.h +++ b/src/crypto/hmac_sha512.h @@ -17,7 +17,7 @@ class CHMAC_SHA512 CSHA512 inner; public: - static const size_t OUTPUT_SIZE = 64; + static constexpr size_t OUTPUT_SIZE = 64; CHMAC_SHA512(const unsigned char* key, size_t keylen); CHMAC_SHA512& Write(const unsigned char* data, size_t len) diff --git a/src/crypto/ripemd160.h b/src/crypto/ripemd160.h index a06a3255e21a..15b28a8c412f 100644 --- a/src/crypto/ripemd160.h +++ b/src/crypto/ripemd160.h @@ -17,7 +17,7 @@ class CRIPEMD160 uint64_t bytes{0}; public: - static const size_t OUTPUT_SIZE = 20; + static constexpr size_t OUTPUT_SIZE = 20; CRIPEMD160(); CRIPEMD160& Write(const unsigned char* data, size_t len); diff --git a/src/crypto/sha1.h b/src/crypto/sha1.h index fcb96ee6a72c..1327ccfab580 100644 --- a/src/crypto/sha1.h +++ b/src/crypto/sha1.h @@ -17,7 +17,7 @@ class CSHA1 uint64_t bytes{0}; public: - static const size_t OUTPUT_SIZE = 20; + static constexpr size_t OUTPUT_SIZE = 20; CSHA1(); CSHA1& Write(const unsigned char* data, size_t len); diff --git a/src/crypto/sha256.h b/src/crypto/sha256.h index 3ac771c5d0db..2cb7f88282a5 100644 --- a/src/crypto/sha256.h +++ b/src/crypto/sha256.h @@ -18,7 +18,7 @@ class CSHA256 uint64_t bytes{0}; public: - static const size_t OUTPUT_SIZE = 32; + static constexpr size_t OUTPUT_SIZE = 32; CSHA256(); CSHA256& Write(const unsigned char* data, size_t len); diff --git a/src/support/lockedpool.h b/src/support/lockedpool.h index c4966bbbbeaa..da597e0c4a65 100644 --- a/src/support/lockedpool.h +++ b/src/support/lockedpool.h @@ -131,11 +131,11 @@ class LockedPool * allocation and deallocation overhead. Setting it too high allocates * more locked memory from the OS than strictly necessary. */ - static const size_t ARENA_SIZE = 256*1024; + static constexpr size_t ARENA_SIZE = 256*1024; /** Chunk alignment. Another compromise. Setting this too high will waste * memory, setting it too low will facilitate fragmentation. */ - static const size_t ARENA_ALIGN = 16; + static constexpr size_t ARENA_ALIGN = 16; /** Callback when allocation succeeds but locking fails. */ From 34a0f6fba93db65e0bf45990baeb95e10575a723 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Wed, 3 Jun 2026 13:44:28 +0100 Subject: [PATCH 2/4] addrman: Make `==` comparitor `const` --- src/addrman.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addrman.h b/src/addrman.h index 94e7d3e65379..b25212ba4eec 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -69,7 +69,7 @@ struct AddressPosition { const int bucket; const int position; - bool operator==(AddressPosition other) { + bool operator==(AddressPosition other) const { return std::tie(tried, multiplicity, bucket, position) == std::tie(other.tried, other.multiplicity, other.bucket, other.position); } From f1842615a32f1b1d35f7c79afe464fcfbd44bbce Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Wed, 3 Jun 2026 13:48:09 +0100 Subject: [PATCH 3/4] test: util: Add stricter `requires` on optional streaming --- src/test/util/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/util/common.h b/src/test/util/common.h index 2fa4cb3cfe7e..8c409824dfae 100644 --- a/src/test/util/common.h +++ b/src/test/util/common.h @@ -41,6 +41,7 @@ inline std::ostream& operator<<(std::ostream& os, const T& e) } template + requires requires(std::ostream& os, const T& t) { os << t; } inline std::ostream& operator<<(std::ostream& os, const std::optional& v) { return v ? os << *v From 729dbc515914628d532244625457ee39b9c662cc Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Wed, 3 Jun 2026 13:53:24 +0100 Subject: [PATCH 4/4] test(ipc): Add `namespace` to prevent ODR conflict --- src/ipc/test/ipc_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ipc/test/ipc_test.cpp b/src/ipc/test/ipc_test.cpp index 45f5751487c8..4ff854e9a21c 100644 --- a/src/ipc/test/ipc_test.cpp +++ b/src/ipc/test/ipc_test.cpp @@ -31,6 +31,7 @@ static_assert(ipc::capnp::messages::DEFAULT_BLOCK_RESERVED_WEIGHT == DEFAULT_BLO static_assert(ipc::capnp::messages::DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS == DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS); //! Remote init class. +namespace { class TestInit : public interfaces::Init { public: @@ -38,6 +39,7 @@ class TestInit : public interfaces::Init std::unique_ptr makeEcho() override { return interfaces::MakeEcho(); } void stop() override { stop_called.store(true); } }; +} // namespace //! Generate a temporary path with temp_directory_path and mkstemp static std::string TempPath(std::string_view pattern)