GCC -Wuninitialized / -Wmaybe-uninitialized issues

Indeed this is a known problem in gcc.
gcc is notorious for reporting incorrect uninitialized variables.
The shortcomings have been duly noted and there is a initiative to overcome the shortcomings:
Better Uninitialized Warnings:

The GNU Compiler Collection warns about the use of uninitialized variables with the option -Wuninitialized. However, the current implementation has some perceived shortcomings. On one hand, some users would like more verbose and consistent warnings. On the other hand, some users would like to get as few warnings as possible. The goal of this project is to implement both possibilities while at the same time improving the current capabilities.

The initiative aims at providing better warnings and it quotes a example case similar as your case. The relevant portion being:

What an user understands as a false positive may be different for the particular user. Some users are interested in cases that are hidden because of actions of the optimizers combined with the current environment. However, many users aren’t, since that case is hidden because it cannot arise in the compiled code. The canonical example is

int x;
if (f ())
     x = 3;
return x;

where ‘f’ always return non-zero for the current environment, and thus, it may be optimized away. Here, a group of users would like to get an uninitialized warning since ‘f’ may return zero when compiled elsewhere. Yet, other group of users would consider spurious a warning about a situation that cannot arise in the executable being compiled.

Leave a Comment