Remove unnecessary const_cast #15389

pull scravy wants to merge 1 commits into bitcoin:master from scravy:patch-1 changing 1 files +1 −1
  1. scravy commented at 5:25 PM on February 12, 2019: contributor

    The const_cast

    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:

    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.

  2. in src/validation.cpp:4350 in f24256e469 outdated
    4346 | @@ -4347,7 +4347,7 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
    4347 |          return true;
    4348 |  
    4349 |      try {
    4350 | -        CBlock &block = const_cast<CBlock&>(chainparams.GenesisBlock());
    4351 | +        const CBlock &block = chainparams.GenesisBlock();
    


    promag commented at 5:31 PM on February 12, 2019:

    nit, const CBlock& block.


    scravy commented at 5:50 PM on February 12, 2019:

    Fixed the pointer alignment according to .clang-format.

  3. promag commented at 5:45 PM on February 12, 2019: member

    utACK f24256e.

  4. promag commented at 5:52 PM on February 12, 2019: member

    IMO for such tiny changes you can push already squashed.

  5. DrahtBot commented at 5:58 PM on February 12, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15118 (Refactor block file logic by jimpo)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  6. MarcoFalke added the label Refactoring on Feb 12, 2019
  7. Remove unnecessary const_cast
    Signed-off-by: Julian Fleischer <julian@thirdhash.com>
    5039e4b61b
  8. scravy force-pushed on Feb 12, 2019
  9. scravy commented at 9:26 PM on February 12, 2019: contributor

    Squashed and rebased.

  10. promag commented at 9:38 PM on February 12, 2019: member

    utACK 5039e4b.

  11. MarcoFalke commented at 9:43 PM on February 12, 2019: member

    ACK 5039e4b61b (checked that the objdump is the same when compiled with clang 7 on my machine)

  12. practicalswift commented at 6:20 AM on February 13, 2019: contributor

    utACK 5039e4b61beb937bad33ac4300cc784642782589

    Good catch and nice cleanup!

  13. laanwj merged this on Feb 13, 2019
  14. laanwj closed this on Feb 13, 2019

  15. laanwj referenced this in commit cbe7efe9ea on Feb 13, 2019
  16. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-20 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me