sometimes uninitialized warning

Should the following:

  int foo(int a)
  int b;

  if (a != 4)

  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.