The warning appears in the -O2 (or any other optimization) mode along with the option -Wmaybe-uninitialized
turned on. The -Wmaybe-uninitialized
option is also turned on with -Wall
and with any of the optimization modes enabled.
The reason for this as per GCC documentation is:
-Wmaybe-uninitialized
For an automatic (i.e. local) variable, if there exists a path from the function
entry to a use of the variable that is initialized, but there exist some other
paths for which the variable is not initialized, the compiler emits a warning if
it cannot prove the uninitialized paths are not executed at run time.
These warnings are only possible in optimizing compilation, because otherwise
GCC does not keep track of the state of variables. These warnings are made optional because GCC may not be able to determine
when the code is correct in spite of appearing to have an error.
Then follows an example of how the above mentioned scenario can happen.