User account creation filtered due to spam.

Bug 48414

Summary: Missing "uninitialized" warning in simple switch
Product: gcc Reporter: Ricardo Garcia <gccbugs>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: ajv-198-093-0407, manu
Priority: P3    
Version: 4.5.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

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: ");
        int c = getchar();

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

        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.

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

    if (argc > 1) {
        c = 1;
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 ***