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

            Bug ID: 95157
           Summary: Missing -Wtautological-compare warning
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon.marchi at polymtl dot ca
  Target Milestone: ---

Using this code:

volatile short insn;

int main()
{
  if (insn < 0 && insn > 3) {
      return 1;
  } else {
      return 0;
  }
}


clang 11 warns, but gcc doesn't:

$ gcc-10 test.c -c -Wall
$ g++-10 test.c -c -Wall
$ clang-11 test.c -c -Wall 
test.c:5:16: warning: overlapping comparisons always evaluate to false
[-Wtautological-overlap-compare]
  if (insn < 0 && insn > 3) {
      ~~~~~~~~~^~~~~~~~~~~
1 warning generated.
$ clang++-11 test.c -c -Wall
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is
deprecated [-Wdeprecated]
test.c:5:16: warning: overlapping comparisons always evaluate to false
[-Wtautological-overlap-compare]
  if (insn < 0 && insn > 3) {
      ~~~~~~~~~^~~~~~~~~~~
1 warning generated.


I think -Wtautological-compare should trigger here.

Reply via email to