The code flow analysis that the optimiser performs allows it to detect potential problems that normal (and faster) compilation cannot detect. The problem was always there, the compiler just didn't check for it.
Even when this warning is issued, it may in fact not be a problem due to the actual usage of the function in practice; the compiler will assume that all possible values of the types of its arguments (and any external variables used within the function) may occur in all possible combinations - leading to at least one path where the variable is used without being assigned a value. Your actual usage will have a far more restrictive set of possible states, so the path may never occur in practice. The simple solution is just to initialise the variable if only to shut the compiler up - it will cost you nothing.
I always use the optimiser as a form of poor-man's static analysis even when I ultimately do not intend to use it in the production code. Equally, I often use more than one compiler for the same reason. Some compilers perform checks that others don't, or they generate differently worded messages for the same errors, which often helps in their interpretation for some of the more obtuse messages.
Quote:
I trust the compiler more when the -g
flag is on
While it is true that if a compiler has a bug it is likely to be in the optimiser (it being the most complex part), for a mature compiler such as GCC, this would be a very rare find. Conversely people often find that their working code fails when optimised; most often the code was always flawed (perhaps it relied on undefined or compiler defined behaviour), and the optimiser has just exposed that flaw. So I suggest if you find your code breaking under optimisation, suspect the code before the compiler - Occam's Razor applies.