https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118593

            Bug ID: 118593
           Summary: False-positive warning about applying bitwise
                    operation to a boolean expression
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristoimenov at gmail dot com
  Target Milestone: ---

The following code produces three warnings about applying ‘~’ on a boolean
expression. Clearly, the first bitwise NOT is applied to an unsigned integer;
the second is also applied to an unsigned integer, as ~ and type cast are
right-associative and with the same precedence; whereas the third bitwise NOT
is actually applied to a boolean expression. However, all three initialisers
produce the same warning.

```
int main()
{
    unsigned s=42, r1=~((unsigned)(s==42)), r2=~(unsigned)(s==42), r3=~(s==42);
}
```

```
$ gcc -Wbool-operation a.c
a.c: In function ‘main’:
a.c:3:22: warning: ‘~’ on a boolean expression [-Wbool-operation]
    3 |     unsigned s=42, r=~(unsigned)(s==42);
      |                      ^
a.c:3:22: note: did you mean to use logical not?
    3 |     unsigned s=42, r=~(unsigned)(s==42);
      |                      ^
      |                      !
```

Reply via email to