refactor: replace all implicit C-style const/const+reinterpret with explicit casts #27126

pull PastaPastaPasta wants to merge 1 commits into bitcoin:master from PastaPastaPasta:replace-implicit-const-cast changing 4 files +33 −33
  1. PastaPastaPasta commented at 10:59 PM on February 19, 2023: contributor

    This PR aims to replace all implicit C-style const (and const+reinterpret) casts with explicit casts to improve the code's readability and maintainability.

    Implicit casts can cause subtle issues and can introduce undefined behavior. Explicit casting improves the code's readability and makes it easier to understand the intent of the code. Additionally, it makes it easier for developers to grep for these casts and do more substantial refactoring that may eliminate the need for casting altogether. By doing this change, it will be easier to maintain this code in the future.

    Overall, these changes are straightforward and only involve replacing existing code with explicit casts. The changes improve the readability and maintainability of the codebase and do not introduce any new functionality.

    Additionally, as this only replaces const_casts; there should be very few (if any) conflicts with other PRs.

  2. DrahtBot commented at 10:59 PM on February 19, 2023: 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. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #27491 (refactor: Move chain constants to the util library by TheCharlatan)

    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.

  3. DrahtBot added the label Refactoring on Feb 19, 2023
  4. refactor: replace all implicit C-style const/const+reinterpret with explicit casts 30ac5ae3bc
  5. PastaPastaPasta force-pushed on Feb 19, 2023
  6. in src/test/argsman_tests.cpp:370 in 30ac5ae3bc
     366 | @@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases)
     367 |      const char *argv_test[] = {"ignored", "-nofoo", "-foo", "-nobar=0"};
     368 |      testArgs.SetupArgs({foo, bar});
     369 |      std::string error;
     370 | -    BOOST_CHECK(testArgs.ParseParameters(4, (char**)argv_test, error));
     371 | +    BOOST_CHECK(testArgs.ParseParameters(4, const_cast<char**>(argv_test), error));
    


    maflcko commented at 3:05 PM on February 20, 2023:

    Instead of changing one cast to another, it might be better to just use a span? But not sure if such refactoring is still worth it, then


    PastaPastaPasta commented at 3:14 PM on February 20, 2023:

    That might make sense. If I get more time sometime soon, I'll see if I can easily span-ify it. Overall, I prefer no cast over any cast; but if I cannot figure it out for some reason then I think it makes sense to still include it in this PR


    fanquake commented at 11:23 AM on March 8, 2023:

    That might make sense. If I get more time sometime soon, I'll see if I can easily span-ify it.

    There doesn't seem to be much buy-in to making this change, and there's no real rush in any case, so feel free to look at using the Spans. Could probably mark this as a draft for now, if that is what you're going to look at.

  7. achow101 commented at 4:27 PM on April 25, 2023: member

    This PR does not seem to have conceptual support. Please leave a comment if you would like this to be reopened.

  8. achow101 closed this on Apr 25, 2023

  9. bitcoin locked this on Apr 24, 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:13 UTC

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