I've compiled the following code using `gcc -std=c99 -O -g -Wall gcctest.c -o

#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)
static void foo(void)
    for (int i; i < 32; ++i)
        if (!array[i])

int main(void)

    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

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


Reply via email to