http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60170

            Bug ID: 60170
           Summary: No -Wtype-limits warning with -O1
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

For the expression "-4L == (*g = l == 0)": 
1) gcc -O0 warns that the comparison is always false, which is desired. 
2) with gcc -O1, the expression is optimized away, and the function fn1
directly returns "0". No -Wtype-limits warning for this expression. 

Since warning is a way to notify the programmers of potential bugs, IMHO it may
still be necessary to report the warning at -O1, even though Gcc has no policy
to ensure the warning consistency between -O0 and -O. 



$: cat s.c
unsigned short *g;
int fn1() {
  unsigned char ***const l = 0;
  return -4L == (*g = l == 0);
}
$: gcc-trunk -Wtype-limits -c s.c
s.c: In function ‘fn1’:
s.c:4:14: warning: comparison is always false due to limited range of data type
[-Wtype-limits]
   return -4L == (*g = l == 0);
              ^
$: gcc-trunk -Wtype-limits -c -O1 s.c
$: gcc-trunk --version
gcc-trunk (GCC) 4.9.0 20140210 (experimental)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Reply via email to