https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106774
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Blocks| |87403 --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Frank Heckenbach from comment #2) > This should cover all cases mentioned: > > void t (bool a, int i, float e, double f) > { > // Boolean literal comparisons > if (a == true) // better: if (a) > return; > if (a == false) // better: if (!a) > return; > if (a != true) // better: if (!a) > return; > if (a != false) // better: if (a) > return; > // also reversed to be sure > if (true == a) // better: if (a) > return; > if (false != a) // better: if (a) > return; These are definitely coding style, and I don't think a warning is warranted. > > // Integer comparisons to Boolean literals > if (i == true) // better: if (i == 1) Or maybe it was meant to be ((bool)i = true). Warning for these does seem more useful IMO. The arithmetic promotions from bool to int (or float) mean the comparison doesn't do what it appears to do, and there seems no reason to use a true/false literal there. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403 [Bug 87403] [Meta-bug] Issues that suggest a new warning