One example of a language without that implicit conversion is Java. It's fairly annoying to have to put a "!= 0" whenever you want to convert a number to a boolean, but it does avoid a lot of programming mistakes within if conditions.
One example of a language without that implicit conversion is Java. It's fairly annoying to have to put a "!= 0" whenever you want to convert a number to a boolean, but it does avoid a lot of programming mistakes within if conditions.
But it is sad that in $current_year, we're still fighting boring, solved problems.
In practice you tend to see such casts in code where we directly needed the integer. I think Clippy (Rust's linter) proposes them where you've written if some_bool { 1 } else { 0 } because well, that's what the as cast does anyway.
I'm not saying C++ is a great language, it's not, but if you remove the secu then shoot you in the foot, it's your fault.
-Wall -Werror does not catch the error described in the blog.
It does get caught by a static analyzer though [0].
The software I'm working on is safety-critical. I enabled every relevant checker relevant for certificates and tons of additional checkers related to usability and readability. clang-tidy now takes 3x the time it takes to compile :S I ended up splitting off a few checkers in particular into their own separate job.
Some checkers are also quite broken. bugprone-unchecked-optional-access is very broken. It caused hangs, it caused crashes, it caused out-of-memory issues. Fortunately, our use of std::optional can mostly be refactored away but doing so is a significant change in the codebase.
2. This would be caught by static analyzer
See Compiler Explorer example here [0]
In this [0] example I shared in other related comments, the static analyzer suppressed warnings in such headers.
> 126 warnings generated.
> Suppressed 124 warnings (124 in non-user code).