https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105557
            Bug ID: 105557
           Summary: -Wtautological-compare doesn't warn about bitwise
                    expressions that always evaluate to true or false
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: garsilva at embeddedor dot com
  Target Milestone: ---

Clang[1] emits warnings on the following code, which contains bitwise
expressions that always evaluate to true:

#include <stdlib.h>

enum Flags {
    FLAG_A = 0b001,
    FLAG_B = 0b010,
    FLAG_C = 0b100,
};

void a();
void b();
void c();

void f(enum Flags f) {
    if (!!(f | FLAG_A)) {
        a();
    } else if (!!(f | FLAG_B)) {
        b();
    } else if (!!(f | FLAG_C)) {
        c();
    } else {
        abort();
    }
}

and it seems that GCC is not able to detect the above tautological expressions.

[1] https://godbolt.org/z/ax6vhczP1
  • [Bug c/105557] New: -Wtautolog... garsilva at embeddedor dot com via Gcc-bugs

Reply via email to