This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/48001] New: -Wuninitialized warning caught a different way for printf and ++ in loop
- From: "jerome.borme at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 5 Mar 2011 20:43:35 +0000
- Subject: [Bug middle-end/48001] New: -Wuninitialized warning caught a different way for printf and ++ in loop
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: jerome.borme@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.