Hello,
I've compiled the following code using `gcc -std=c99 -O -g -Wall gcctest.c -o
gcctest':
<<<<<<<<<<<<<<<
#include <stdio.h>
static int array[32];
#if 0 // If '#if 1' is used, GCC warns correctly about the use of uninitialized
variable 'i' below.
void foo(void);
void foo(void)
#else
static void foo(void)
#endif
{
for (int i; i < 32; ++i)
{
if (!array[i])
break;
}
}
int main(void)
{
foo();
return 0;
}
>>>>>>>>>>>>>>>
The problem is that GCC 4.5.1 does not warn about the use of the uninitialized
variable `i' on the line containing `if (!array[i])'. GCC 3.4.6 did this
correctly.
A perhaps interesting fact is that when the snippet is compiled with `#if 1'
instead of `#if 0', GCC 4.5.1 does warn correctly.
Thanks, Jelle
--
Summary: gcc won't warn about an uninitialized value
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jellegeerts at gmail dot com
GCC host triplet: mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45467