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

           Summary: -Wuninitialized warning caught a different way for
                    printf and ++ in loop
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: jerome.bo...@gmail.com


I checked bug meta-bug #24639, also bug #43361 and bug #27589, but I could not
b sure this is a duplicate. The 3rd test below is the surprising one.

gcc -c -Wuninitialized test.c

/* 1st test */
int main () {
  int i, x ;
  x++ ;       // printf ("%d", x) ; would give the same result
  return 0 ;
}
-->  ‘x’ is used uninitialized in this function
This is expected, we should be incrementing x without first initialization. It
works the same for x++ and printf x.

/* 2nd test */
#include <stdio.h>
int main () {
  int i, x ;
  for (i = 0 ; i < 10 ; i++) printf ("%d", x) ;
  return 0 ;
}
--> ‘x’ may be used uninitialized in this function
I think this corresponds to bug #27589. We should not printf x without
initializing, but the compiler cannot be sure if we will actually be printed or
not before  evaluating the “for” test at runtime.

/* 3rd test */
int main () {
  int i, x ;
  for (i = 0 ; i < 10 ; i++) x++ ;
  return 0 ;
}
--> No warning at all.
This is surprising:
* Outside a loop, both printf and x++ give the same warning.
* Inside a loop, printf will give a warning, while x++ will not do it.

Reply via email to