Skip to content

Conversation

PastaPastaPasta
Copy link
Contributor

@PastaPastaPasta PastaPastaPasta commented Dec 20, 2021

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 21, 2021

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

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.

Conflicts

No conflicts as of last run.

@maflcko
Copy link
Member

maflcko commented Dec 21, 2021

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 9db89e1

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

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

ACK 9db89e1

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.

@maflcko
Copy link
Member

maflcko commented Dec 21, 2021

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.

@PastaPastaPasta PastaPastaPasta changed the title refactor: use braced init for integer constants instead of c style casts refactor: use braced init for integer literals instead of c style casts Dec 21, 2021
@PastaPastaPasta
Copy link
Contributor Author

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.

@PastaPastaPasta
Copy link
Contributor Author

@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.

@PastaPastaPasta
Copy link
Contributor Author

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

@PastaPastaPasta
Copy link
Contributor Author

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?

@ajtowns
Copy link
Contributor

ajtowns commented Jan 28, 2022

24032 will need a rebase after #23508 is merged anyway

@glozow
Copy link
Member

glozow commented Sep 26, 2022

@PastaPastaPasta are you still working on this?

@PastaPastaPasta
Copy link
Contributor Author

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.

@PastaPastaPasta
Copy link
Contributor Author

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.

Copy link
Contributor

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

ACK f2fc03e
Verified no values are being changed.

@maflcko
Copy link
Member

maflcko commented Jan 5, 2023

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

@maflcko maflcko merged commit 3212d10 into bitcoin:master Jan 5, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 6, 2023
@PastaPastaPasta PastaPastaPasta deleted the use-braced-init branch February 19, 2023 17:44
@bitcoin bitcoin locked and limited conversation to collaborators Feb 19, 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.

7 participants