On 09/05/16 18:45, Joseph Myers wrote: > On Mon, 5 Sep 2016, Marek Polacek wrote: > >> Still not sure about other operations. I guess no one would >> object to warning on bool1 % bool2, but should we warn for >> bool1 + bool2? > > I think boolean addition (with the result interpreted as an integer, not > converted back to boolean) is perfectly reasonable - counting the number > of flags that are true, for example (say if there are several conditions > and it's an error for more than one of them to hold - of course that would > be bool1 + bool2 + bool3 + bool4, etc.). >
Yes, that's what I had in mind too. I think I even remember having seen code like this, which is OK as long as the result is stored in an integer variable. But "if (bool1 + bool2)" should be written as "if (bool1 | bool2)", and "if (bool1 * bool2)" should be written as "if (bool1 & bool2)". I think a warning for boolean + and * suggesting to use | and & is justified for clarity. Bernd.