No description provided.
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-
kazcw commented at 8:21 PM on June 8, 2016: contributor
- kazcw renamed this:
developer notes: deprecate C-style casts
developer notes: deprecate C-style casts + updates for C++11
on Jun 8, 2016 -
dcousens commented at 10:51 PM on June 8, 2016: contributor
concept ACK
-
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.
-
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.
- laanwj added the label Docs and Output on Jun 9, 2016
-
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_castand 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.
-
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.
-
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.
-
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)
-
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.
-
654a211622
developer notes: updates for C++11
- boost::scoped_ptr is obsolete - std::vector::data replaces begin_ptr / end_ptr
- kazcw force-pushed on Jun 9, 2016
-
kazcw commented at 5:02 PM on June 9, 2016: contributor
Removed the statement on C-style casts.
- laanwj renamed this:
developer notes: deprecate C-style casts + updates for C++11
developer notes: updates for C++11
on Jun 10, 2016 - laanwj merged this on Jun 10, 2016
- laanwj closed this on Jun 10, 2016
- laanwj referenced this in commit 67db011e12 on Jun 10, 2016
- codablock referenced this in commit 0cb9aacd93 on Sep 16, 2017
- codablock referenced this in commit c843ba7507 on Sep 19, 2017
- codablock referenced this in commit acbda5d16d on Dec 22, 2017
- andvgal referenced this in commit 2592197f5a on Jan 6, 2019
- MarcoFalke locked this on Sep 8, 2021