Merge #15389: Remove unnecessary const_cast

5039e4b61b Remove unnecessary const_cast (Julian Fleischer)

Pull request description:

  The const_cast

  ```C++
  CBlock &block = const_cast<CBlock&>(chainparams.GenesisBlock());
  ```

  is not necessary as all the functions invoked form this block receive a `const CBlock&` anyway. Simply add the `const` to `block`:

  ```C++
  const CBlock& block = chainparams.GenesisBlock();
  ```

  Casting away `const`, especially from something as precious as the genesis block, feels really weird to me as a reader of bitcoin-core source code.

Tree-SHA512: 0290b2cabb216a60655ded153ed1f213c051fb216cec6f3f810f8b760e276f8def86eb696c492e89631682531e215f56d7897b59685d3aa787bcd80cc4f86c90
This commit is contained in:
Wladimir J. van der Laan 2019-02-13 17:06:57 +01:00
commit cbe7efe9ea
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D

View file

@ -4347,7 +4347,7 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
return true;
try {
CBlock &block = const_cast<CBlock&>(chainparams.GenesisBlock());
const CBlock& block = chainparams.GenesisBlock();
CDiskBlockPos blockPos = SaveBlockToDisk(block, 0, chainparams, nullptr);
if (blockPos.IsNull())
return error("%s: writing genesis block to disk failed", __func__);