4 ms·
Hmm, I wonder if that's actually true. I don't have GCC 7 anywhere to actually test it, but the documentation[1] states: -Wint-in-bool-context Warn for susp
by fjarlq 10y ago
Hmm, I wonder if that's actually true. I don't have GCC 7 anywhere to actually test it, but the documentation[1] states:
-Wint-in-bool-context
Warn for suspicious use of integer values where boolean values are expected, such as conditional expressions (?:) using non-boolean integer constants in boolean context, like
if (a <= b ? 2 : 3)
Or left shifting of signed integers in boolean context, like
for (a = 0; 1 << a; a++);
Likewise for all kinds of multiplications regardless of the data type. This warning is enabled by `-Wall`.
[1]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
- ChuckMcM 10y agoI'm guessing (again I can't really test it yet) that it will warn on it and suggest if (int_value != 0) { ... } To be clear about what I mean.
- bonzini 10y agoI don't think it will warn for this simple case.
- ajdlinux 10y agoI've just tested against GCC master and can confirm that -Wint-in-bool-context does not trigger on this very, very standard case. Per the examples in the documentation, it does trigger when you do something silly like "if (i < 3 ? 7 : 0)". In fact if you read the documentation and the warning messages more closely, it's looking for suspicious use of integer constants, not integer variables.
- ChuckMcM 10y agoAwesome, and I missed the bit about constants.