max66's answer is just fine, but as someone who has implemented various parsers and even simple compilers over the years let me offer you some more context.
Let's first get this out of the way: It would only be a bug if the standard mandated it (or GCC documented the behavior you want, as a language extension).
However, the standard cannot mandate that unreachable code be removed because detecting which code is unreachable is an undecidable problem. This can be trivially proven by reducing it to the halting problem. Assume that comp
is a Turing machine computation, n
is a non-negative integer value (of an unbounded type) and halts
is a function that executes up to n
number of iterations of comp
and returns whether or not a halting state was reached. Now consider the following pseudo-code:
if ( halts(comp, n) )
print "Halted.";
Determining whether or not the print
statement is reachable therefore requires solving the halting problem for comp
which is an arbitrary Turing machine calculation – not possible.
Now you might say that this is a very contrived reasoning, and has nothing to do with obviously decidable cases such as your example. However, consider that intuitive assumptions about "obviousness" and the wording of the language standard are two very different things. In other words, the committee would need to select a subset of "detectable" cases and carefully specify under which circumstances the implementation is required to detect unreachable code (and, in time, prune the evaluation tree). Compiler vendors would then be obliged to spend a possibly great deal of time implementing these rules. (Remember that software traditionally operates on "hard-coded" logical rules and does not "intuit" its required behavior. Maybe one day we'll have AI compilers that automagically do "the right thing", but we're currently not even close to that.)
Long story short – while such an approach could be taken, resources are limited, and there are simply a great many more important issues to be solved. The inconvenience of needing to be explicit about the branch structure by adding an else
, in your example, is indeed minor.