https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79374

            Bug ID: 79374
           Summary: missing sometimes-uninitialized warning in switch
                    statement
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hermantenbrugge at home dot nl
  Target Milestone: ---

The code below:

int tst(int);

int
tst (int sel)
{
  int rv;

  switch (sel) {
  case 1: break;
  default: rv = 0;
           break;
  }
  return rv;
}

compiled with 'gcc -S -O3 -Wall tst.c' results in no warning in gcc 6.3.1 and
gcc 7.0.1 (head)
When compiled with clang 3.8.1 with same compiler options I get:

tst.c:9:8: warning: variable 'rv' is used uninitialized whenever switch case is
taken [-Wsometimes-uninitialized]
  case 1: break;
       ^
tst.c:13:10: note: uninitialized use occurs here
  return rv;
         ^~
tst.c:6:9: note: initialize the variable 'rv' to silence this warning
  int rv;
        ^
         = 0
1 warning generated.

This is a very reduced test case and in the real code it was much harder to see
that rv was uninitialized.

I now that bug '44042' was closed as 'RESOLVED WONTFIX' but clang gives the
correct warning.

Reply via email to