[cfe-users] Issue in -Wtautological-constant-out-of-range-compare?

Fred fredm at spamcop.net
Sat Dec 14 03:17:10 PST 2013


Hi all,
I am seeing the -Wtautological-constant-out-of-range-compare warning for the first time.

With this Apple clang version:
$ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

In this program:
#include <stdio.h>

typedef enum o {
    O_1 = 0,
    O_2,
} o;

int main(int argc, char** argv) {
  enum o e1 = -1;

  if( e1 >= 2 ) {
    printf( "That's not right\n" );
  }

  printf("e1:%d\n",e1);

  return 0;
}

Compiled thus, I get the warning that my if test above will always evaluate as false:
$ clang -Wall -std=c89 t1.c 
t1.c:11:10: warning: comparison of constant 2 with expression of type 'enum o'
      is always false [-Wtautological-constant-out-of-range-compare]
  if( e1 >= 2 ) {
      ~~ ^  ~
1 warning generated.

That is demonstrably untrue:
$ ./a.out 
That's not right
e1:-1

Does this error also occur in the mainline clang? I am unsure whether to raise the issue with Apple or the clang developers.

Thanks,
Fred



More information about the cfe-users mailing list