GCC Bugzilla will be upgraded from version 4.4.9 to 5.0rc3 on Saturday, April 25, starting around 17:00 UTC. The upgrade process should only last a few minutes. Check bug 64968 for details.

Bug 37148

Summary: -Wunintialized fails in the face of conditional initialization.
Product: gcc Reporter: thutt
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: dberlin, gcc-bugs, manu, mark, mueller, P.Schaffnit, pinskia, satyam, thutt
Priority: P3    
Version: 4.1.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description thutt 2008-08-18 13:31:34 UTC
Although I demonstrated this using 4.1.2 on my host, it probably affects
other versions as well.

As the following code shows:

    gcc -c -O1 -Wall -Werror uninitialized-warning.c

    extern void called_function(unsigned p);
    extern unsigned g;

    void
    f0(unsigned parm)
    {
       unsigned v;
       if (parm == 0) {
          v = 4;
       }
       called_function(v);
    }

    void
    f1(unsigned parm)
    {
       unsigned v;
       if (parm == 0) {
          v = 4;
       } else {
          g = 0;
       }
       called_function(v);
    }

    void
    f2(unsigned parm)
    {
       unsigned v;
       called_function(v);
    }

gcc does not produce the 'uninitialized' warning when the automatic
variable is conditionally assigned.

This gives a very bad false sense of security that the automatic
variables are indeed initialized.
Comment 1 Manuel López-Ibáñez 2008-08-18 13:46:02 UTC
CCP removes the uninitialized use.

*** This bug has been marked as a duplicate of 18501 ***