[cfe-users] sometimes uninitialized warning

Morrell, Michael michael.morrell at intel.com
Tue Feb 25 11:29:16 PST 2014


Should the following:

  int foo(int a)
{
  int b;

  if (a != 4)
    __builtin_unreachable();

  if (a == 4)
     b  = 2;

  return b;

give a warning?

The compiler (with -Wsometimes-uninitialized) says that b might not be initialized if the second "if" condition is false.

I agree the code is a little silly, but the first "if" condition should be enough to convince the compiler that everything's OK.  I'd expect the optimizer to even remove all the "if"s and have this function simply return "2" unconditionally.

  Michael



More information about the cfe-users mailing list