Should unreachable code be considered an error?

Timon Gehr timon.gehr at gmx.ch
Thu Aug 18 05:53:58 PDT 2011


On 08/18/2011 02:19 PM, Bernard Helyer wrote:
> On Thu, 18 Aug 2011 14:14:08 +0200, Timon Gehr wrote:
>
>> The trouble with making dead code an error in general is that the
>> compiler is not able to detect dead code in most cases.
>
> I'm talking about the unambiguous cases, the ones where a basic block has
> no parents (i.e. there is no way to enter that code block).
>
>> Also, since the compiler is allowed to assume that any assert(0); is
>> dead code, assert(0) would always be a compile time error. =)
>
> No, only if statements followed the assert(0) (which marks the control
> flow block as terminated, just like return).

I was half joking. Fact is, if assert(0); is not dead code, the program 
is in error.


More information about the Digitalmars-d mailing list