Skip to content

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

Closed
PastaPastaPasta wants to merge 1 commit into
bitcoin:masterfrom
PastaPastaPasta:replace-implicit-const-cast
Closed

refactor: replace all implicit C-style const/const+reinterpret with explicit casts#27126
PastaPastaPasta wants to merge 1 commit into
bitcoin:masterfrom
PastaPastaPasta:replace-implicit-const-cast

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
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.

@DrahtBot

DrahtBot commented Feb 19, 2023

Copy link
Copy Markdown
Contributor

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

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

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.

@PastaPastaPasta
PastaPastaPasta force-pushed the replace-implicit-const-cast branch from 0577c0e to 30ac5ae Compare February 19, 2023 23:00
testArgs.SetupArgs({foo, bar});
std::string error;
BOOST_CHECK(testArgs.ParseParameters(4, (char**)argv_test, error));
BOOST_CHECK(testArgs.ParseParameters(4, const_cast<char**>(argv_test), error));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@achow101

Copy link
Copy Markdown
Member

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

@achow101 achow101 closed this Apr 25, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants