mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge bitcoin/bitcoin#22597: consensus/params: simplify ValidDeployment check to avoid gcc warning
059171009b0138555f311cedc2553015ff618323 consensus/params: simplify ValidDeployment check to avoid gcc warning (Anthony Towns) Pull request description: Simplifies the ValidDeployment check to only check the upperbound, relying on the lower bound to be trivially true due to enum values starting at the minimum value of the underlying type (which is checked at compile time in deploymentstatus.cpp). Avoids a "comparison always true" warning in some versions of gcc. Fixes #22587 ACKs for top commit: MarcoFalke: review ACK 059171009b0138555f311cedc2553015ff618323 tryphe: retested ACK 059171009b0138555f311cedc2553015ff618323 Tree-SHA512: e53b5d478b46d35ec476d004e3c92803afb874c138dd6ef3848861f4281cc113fe88921bc4ac74fd4decbf318ed776d3f816c3a1185f99dc36a5cfecfff51f7c
This commit is contained in:
parent
8928146bfa
commit
cbd2be8e18
@ -33,7 +33,7 @@ enum BuriedDeployment : int16_t {
|
||||
DEPLOYMENT_BRR,
|
||||
DEPLOYMENT_V19,
|
||||
};
|
||||
constexpr bool ValidDeployment(BuriedDeployment dep) { return DEPLOYMENT_HEIGHTINCB <= dep && dep <= DEPLOYMENT_V19; }
|
||||
constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_V19; }
|
||||
|
||||
enum DeploymentPos : uint16_t {
|
||||
DEPLOYMENT_TESTDUMMY,
|
||||
@ -42,7 +42,7 @@ enum DeploymentPos : uint16_t {
|
||||
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
|
||||
MAX_VERSION_BITS_DEPLOYMENTS
|
||||
};
|
||||
constexpr bool ValidDeployment(DeploymentPos dep) { return DEPLOYMENT_TESTDUMMY <= dep && dep <= DEPLOYMENT_MN_RR; }
|
||||
constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; }
|
||||
|
||||
/**
|
||||
* Struct for each individual consensus rule change using BIP9.
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <consensus/params.h>
|
||||
#include <versionbits.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
VersionBitsCache g_versionbitscache;
|
||||
|
||||
/* Basic sanity checking for BuriedDeployment/DeploymentPos enums and
|
||||
@ -15,3 +17,18 @@ VersionBitsCache g_versionbitscache;
|
||||
static_assert(ValidDeployment(Consensus::DEPLOYMENT_TESTDUMMY), "sanity check of DeploymentPos failed (TESTDUMMY not valid)");
|
||||
static_assert(!ValidDeployment(Consensus::MAX_VERSION_BITS_DEPLOYMENTS), "sanity check of DeploymentPos failed (MAX value considered valid)");
|
||||
static_assert(!ValidDeployment(static_cast<Consensus::BuriedDeployment>(Consensus::DEPLOYMENT_TESTDUMMY)), "sanity check of BuriedDeployment failed (overlaps with DeploymentPos)");
|
||||
|
||||
/* ValidDeployment only checks upper bounds for ensuring validity.
|
||||
* This checks that the lowest possible value or the type is also a
|
||||
* (specific) valid deployment so that lower bounds don't need to be checked.
|
||||
*/
|
||||
|
||||
template<typename T, T x>
|
||||
static constexpr bool is_minimum()
|
||||
{
|
||||
using U = typename std::underlying_type<T>::type;
|
||||
return x == std::numeric_limits<U>::min();
|
||||
}
|
||||
|
||||
static_assert(is_minimum<Consensus::BuriedDeployment, Consensus::DEPLOYMENT_HEIGHTINCB>(), "heightincb is not minimum value for BuriedDeployment");
|
||||
static_assert(is_minimum<Consensus::DeploymentPos, Consensus::DEPLOYMENT_TESTDUMMY>(), "testdummy is not minimum value for DeploymentPos");
|
||||
|
Loading…
Reference in New Issue
Block a user