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

           Summary: uninitialized warning for variables used only in loop
                    body and initialized in the first iteration
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: kip.hi...@gmail.com


Consider the code:

int loop_cond, some_value;

void foo(int arg);
void f() {
     int load, variable;

     load = 1;
     while (loop_cond) {
       if (load) {
          variable = some_value;
          load = 0;
       }

       foo(variable);
     }     
}


gcc -Wall -O1 initialise-warn.c
initialise-warn.c: In function `f':
initialise-warn.c:5: warning: 'variable' might be used uninitialized in this
fun
ction

variable is only used inside the loop, and always set at the beginning of its
first iteration.
The warning is gone if using a conditional instead of a loop, so it seems that
it could easily detect that it is initialised in this case, too. Perhaps it was
optimizing the constant with an if, but the load variable is local and can only
be changed inside the function, so it has no extra restrictions.


The warning appears in gcc 4.5.2 and 4.6.0
The false positive was probably always misreported.

Reply via email to