Bug 48414 - Missing "uninitialized" warning in simple switch
Summary: Missing "uninitialized" warning in simple switch
Status: RESOLVED DUPLICATE of bug 18501
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-02 15:05 UTC by Ricardo Garcia
Modified: 2012-10-24 22:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ricardo Garcia 2011-04-02 15:05:51 UTC
Compiling the following code does not produce any warning, even if the "ret" variable would be used uninitialized in most cases:

#include <stdio.h>

int main(void)
{
        int ret;

        printf("Input something: ");
        fflush(stdout);
        int c = getchar();

        switch (c) {
        case 'a':
                ret = 0;
                break;
        default:
                /* ret still uninitialized. */
                break;
        }

        return ret;
}

Compiled with "gcc -Wall -o uninitialized uninitialized.c" under GCC 4.5.2.
Comment 1 Andy Valencia 2012-10-24 21:54:59 UTC
As of:
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 

the following code also does not get warned about the
possibly uninitialized variable.  I'm quite sure that
gcc *used* to pick this up.

int
main(int argc, char **argv)
{
    int c;

    if (argc > 1) {
        c = 1;
    }
    return(c);
}
Comment 2 Manuel López-Ibáñez 2012-10-24 22:05:41 UTC
This is constant propagation. Old issue. No fix in sight.

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