[Bug c/64637] New: Incorrect location for -Wunused-value warnings in for-loop

chengniansun at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jan 16 22:13:00 GMT 2015


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

            Bug ID: 64637
           Summary: Incorrect location for -Wunused-value warnings in
                    for-loop
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

GCC emits a warning at the start of the for statement, whereas the unused value
is in the next line. This behavior could introduce confusion that the "for"
statement has no effect, which is not true. 



$: cat s.c
void g();

void f(int b) {
  for(int i = 0; i < b; 
      i + b) {
    g();
  }
}
$: 
$: gcc-trunk -Wunused-value -c s.c
s.c: In function ‘f’:
s.c:4:3: warning: statement with no effect [-Wunused-value]
   for(int i = 0; i < b; 
   ^
$: 
$: clang-trunk -Wunused-value -c s.c
s.c:5:9: warning: expression result unused [-Wunused-value]
      i + b) {
      ~ ^ ~
1 warning generated.
$: 
$:


More information about the Gcc-bugs mailing list