developer notes: updates for C++11 #8177

pull kazcw wants to merge 1 commits into bitcoin:master from kazcw:no-c-casts changing 1 files +4 −5
  1. kazcw commented at 8:21 PM on June 8, 2016: contributor

    No description provided.

  2. kazcw renamed this:
    developer notes: deprecate C-style casts
    developer notes: deprecate C-style casts + updates for C++11
    on Jun 8, 2016
  3. dcousens commented at 10:51 PM on June 8, 2016: contributor

    concept ACK

  4. sipa commented at 10:54 PM on June 8, 2016: member

    I'm personally fine with C-style casts for integer types, because for the semantics are simple, unambiguous, and much shorter than using the C++ style.

    However, if people feel strongly about this, I'm fine with strictly avoiding them.

  5. laanwj commented at 5:16 AM on June 9, 2016: member

    I'm fine with C-style casts too for primitive types. No need to change anything there, they're not more magical than anything else.

    For object types and such it makes sense to require c++ casts.

    ACK on the scoped_ptr to unique_ptr change.

  6. laanwj added the label Docs and Output on Jun 9, 2016
  7. dcousens commented at 5:27 AM on June 9, 2016: contributor

    @laanwj it does make searching for casts and points of concern much easier if you use static_cast and the rest of the C++ family of casts. The C-syntax, while more concise in context, often bears a higher intellectual load as to the broader implications of the action in the long run, IMHO.

    The extra safety guarantees are also a boon and pretty excellent for what I would consider safety conscious software.

    It also makes casts even uglier, as they should be.

  8. laanwj commented at 5:32 AM on June 9, 2016: member

    it does make searching for casts and points of concern much easier if you use static_cast and the rest of the C++ family of casts.

    How often do you actually want to search for all casts?

    The extra safety guarantees are also a boon and pretty excellent for what I would consider safety conscious software.

    Can you be more specific here? How are casts of primitive types safer using C++ syntax?

    I know that pointer casts are safer using C++ syntax and as they are the dangerous kind of casting. I agree with using C++ syntax when casting from const to non const pointers, or one kind of pointer to another, but I don't agree doing so for all cases where primitive types are converted.

  9. laanwj commented at 5:34 AM on June 9, 2016: member

    I'm also not looking forward to 20 PRs full of 'convert one type of cast to another'. In the time we run this project we've (as far as I know) never had a bug caused by casting. There's no immediate need here. I wrote those developer suggestions all after having found an issue caused by that particular thing. They're not meant for style preferences.

  10. laanwj commented at 6:24 AM on June 9, 2016: member

    We should mention this one: avoid shadowing vars, and enable -Wshadow #8105 Very sneaky bug introduced by this: #8102 (comment)

  11. dcousens commented at 6:26 AM on June 9, 2016: contributor

    Can you be more specific here? How are casts of primitive types safer using C++ syntax?

    I know that pointer casts are safer using C++ syntax and as they are the dangerous kind of casting.

    Perhaps I mis-indicated that I was referring only to int style casts, the above was a blanket opinion.

    In respect to:

    I agree with using C++ syntax when casting from const to non const pointers, or one kind of pointer to another, but I don't agree doing so for all cases where primitive types are converted.

    I think this is a good compromise. That said, IMHO, primitive conversions can often [but certainly not always] be an indication that the underlying type is over-constrained or just plain wrong. But that problem isn't fixed by this change, it is just made more obvious.

    In light of:

    I'm also not looking forward to 20 PRs full of 'convert one type of cast to another'

    I too think this may be just another nit-pick enabling PR, but, it is certainly a desirable goal... at some point.

  12. developer notes: updates for C++11
    - boost::scoped_ptr is obsolete
    - std::vector::data replaces begin_ptr / end_ptr
    654a211622
  13. kazcw force-pushed on Jun 9, 2016
  14. kazcw commented at 5:02 PM on June 9, 2016: contributor

    Removed the statement on C-style casts.

  15. laanwj renamed this:
    developer notes: deprecate C-style casts + updates for C++11
    developer notes: updates for C++11
    on Jun 10, 2016
  16. laanwj merged this on Jun 10, 2016
  17. laanwj closed this on Jun 10, 2016

  18. laanwj referenced this in commit 67db011e12 on Jun 10, 2016
  19. codablock referenced this in commit 0cb9aacd93 on Sep 16, 2017
  20. codablock referenced this in commit c843ba7507 on Sep 19, 2017
  21. codablock referenced this in commit acbda5d16d on Dec 22, 2017
  22. andvgal referenced this in commit 2592197f5a on Jan 6, 2019
  23. MarcoFalke locked this on Sep 8, 2021
Labels

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-19 12:15 UTC

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