refactor: use braced init for integer literals instead of c style casts #23829

pull PastaPastaPasta wants to merge 1 commits into bitcoin:master from PastaPastaPasta:use-braced-init changing 23 files +47 −47
  1. PastaPastaPasta commented at 6:02 PM on December 20, 2021: contributor

    See #23810 for more context. This is broken out from that PR, as it is less breaking, and should be trivial to review and merge.

    EDIT: Long term, the intention is to remove all C-style casts, as they can dangerously introduce reinterpret_casts. This is one step which removes a number of trivially removable C-style casts

  2. DrahtBot added the label Consensus on Dec 20, 2021
  3. DrahtBot added the label P2P on Dec 20, 2021
  4. DrahtBot added the label Refactoring on Dec 20, 2021
  5. DrahtBot added the label Utils/log/libs on Dec 20, 2021
  6. DrahtBot added the label Validation on Dec 20, 2021
  7. DrahtBot added the label Wallet on Dec 20, 2021
  8. DrahtBot commented at 3:04 AM on December 21, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK aureleoules
    Concept ACK MarcoFalke
    Stale ACK shaavan

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  9. maflcko removed the label Wallet on Dec 21, 2021
  10. maflcko removed the label P2P on Dec 21, 2021
  11. maflcko removed the label Validation on Dec 21, 2021
  12. maflcko removed the label Consensus on Dec 21, 2021
  13. maflcko removed the label Utils/log/libs on Dec 21, 2021
  14. maflcko commented at 9:23 AM on December 21, 2021: member

    Concept ACK. I think this is fine to do because:

    • C++11 braced init is safer, since it has more compile time checks
    • This patch has no conflicts as of now
    • bitcoind is not changed by this patch. I checked clang++ -O2 and g++ -O2 on my system.

    Instead of linking to a pull request for context, I think OP can be improved to give a clear motivation. I think this patch is by itself worthwhile and should be considered independent of the other pull request.

    review ACK 9db89e1efa4332109eb1cb53e153844797a60350

    However, I can also see a point about not changing existing code for style reasons, unless it is touched.

  15. shaavan approved
  16. shaavan commented at 10:18 AM on December 21, 2021: contributor

    ACK 9db89e1efa4332109eb1cb53e153844797a60350

    I agree with the reason given by @MarcoFalke in the above comment.

    1. C++11 braced init is safer since it has more compile-time checks
    2. This patch has no conflicts as of now

    I have reviewed the code, and I think all the appropriate changes are correctly made in this PR.

    However, I can also see a point about not changing existing code for style reasons unless it is touched.

    It makes sense. But these style changes will need to be done sooner or later. And since there are not many conflicts (as of now) for this PR, I think these changes can be safely integrated into the codebase.

  17. maflcko commented at 1:16 PM on December 21, 2021: member

    I took another look here and it seems the changes are incomplete. For example, there are a lot of occurrences in the RPC layer:

            ret.pushKV("height", (int64_t)stats.nHeight);
            ret.pushKV("bestblock", stats.hashBlock.GetHex());
            ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs);
            ret.pushKV("bogosize", (int64_t)stats.nBogoSize);
    

    If the changes are made complete here, it will probably be a change too large and not worth it, so I'll downgrade my ACK to a -0.

  18. PastaPastaPasta renamed this:
    refactor: use braced init for integer constants instead of c style casts
    refactor: use braced init for integer literals instead of c style casts
    on Dec 21, 2021
  19. PastaPastaPasta commented at 4:24 PM on December 21, 2021: contributor

    I took another look here and it seems the changes are incomplete. For example, there are a lot of occurrences in the RPC layer:

            ret.pushKV("height", (int64_t)stats.nHeight);
            ret.pushKV("bestblock", stats.hashBlock.GetHex());
            ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs);
            ret.pushKV("bogosize", (int64_t)stats.nBogoSize);
    

    If the changes are made complete here, it will probably be a change too large and not worth it, so I'll downgrade my ACK to a -0. @MarcoFalke the purpose of this PR is to not be complete :D If it was complete, it would simply be #23810.

    The scope of this PR as I understand it (although original title was misleading), was to only apply this to integer literals (I originally said "integer constants").

    I could expand the scope to all integer constants, but that would potentially be too breaking (according to what you've said). Let's maybe do that in the future.

  20. PastaPastaPasta commented at 6:46 PM on December 28, 2021: contributor

    @MarcoFalke Did my scope clarification (PR only intended to touch integer literals) clarify your concerns? It seems to me this PR only would cause conflicts in two other PRs, so there being lot's of conflicts isn't a concern, and it shouldn't change the binary.

  21. PastaPastaPasta commented at 2:35 AM on January 10, 2022: contributor

    @MarcoFalke if possible, I'd like to continue moving forward with this. Did you have any concerns I haven't addressed?

  22. DrahtBot added the label Needs rebase on Jan 27, 2022
  23. PastaPastaPasta force-pushed on Jan 28, 2022
  24. PastaPastaPasta commented at 4:57 AM on January 28, 2022: contributor

    I have rebased this PR now that #23438 has been merged. @ajtowns @achow101, this PR will cause a few minor and easily resolvable conflicts in your PR (#24032, #23304). Do either of you have an objection to this PR being merged, and hence requiring a rebase in your PRs?

  25. ajtowns commented at 6:23 AM on January 28, 2022: contributor

    24032 will need a rebase after #23508 is merged anyway

  26. DrahtBot removed the label Needs rebase on Jan 28, 2022
  27. DrahtBot added the label Needs rebase on Mar 2, 2022
  28. PastaPastaPasta force-pushed on Mar 7, 2022
  29. DrahtBot removed the label Needs rebase on Mar 7, 2022
  30. DrahtBot added the label Needs rebase on May 12, 2022
  31. PastaPastaPasta force-pushed on May 13, 2022
  32. DrahtBot removed the label Needs rebase on May 13, 2022
  33. DrahtBot added the label Needs rebase on Jun 9, 2022
  34. PastaPastaPasta force-pushed on Jun 9, 2022
  35. DrahtBot removed the label Needs rebase on Jun 9, 2022
  36. DrahtBot added the label Needs rebase on Jul 27, 2022
  37. glozow commented at 10:01 AM on September 26, 2022: member

    @PastaPastaPasta are you still working on this?

  38. PastaPastaPasta commented at 10:02 AM on September 26, 2022: contributor

    I'd love for it to get merged. And would be happy to rebase it. But it seems like most maintainers here don't actually want to review / merge it sadly.

  39. PastaPastaPasta force-pushed on Sep 29, 2022
  40. PastaPastaPasta commented at 7:38 PM on September 29, 2022: contributor

    Rebased :) Hopefully we can get a few reviews on this simple PR. I have liked seeing in my continued rebases as we are refactoring places where ints were previously used and are now using dedicated types that actually mean something.

  41. DrahtBot removed the label Needs rebase on Sep 29, 2022
  42. DrahtBot added the label Needs rebase on Jan 4, 2023
  43. refactor: use braced init for integer constants instead of c style casts f2fc03ec85
  44. PastaPastaPasta force-pushed on Jan 4, 2023
  45. DrahtBot removed the label Needs rebase on Jan 4, 2023
  46. aureleoules approved
  47. aureleoules commented at 10:22 AM on January 4, 2023: member

    ACK f2fc03ec856d7d19a20c482514350cced38f9504 Verified no values are being changed.

  48. maflcko commented at 4:29 PM on January 5, 2023: member

    Checked that f2fc03ec856d7d19a20c482514350cced38f9504 does not change the binary on my system with my compiler

  49. maflcko merged this on Jan 5, 2023
  50. maflcko closed this on Jan 5, 2023

  51. sidhujag referenced this in commit 864cda4aa1 on Jan 6, 2023
  52. PastaPastaPasta deleted the branch on Feb 19, 2023
  53. bitcoin locked this on Feb 19, 2024

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-15 00:14 UTC

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