Should unreachable code be considered an error?

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Sun Oct 2 23:49:04 PDT 2011


Good point.
Dead branch isn't a problem IMO.
In the worst case it's gonna make the binary a few bytes longer.
It's not worth all the effort of trying to make the compiler complain about it.
Besides, it is often required to disable a branch for debugging
purposes, although in those cases I'd rather use a more obvious
solution, like version(none) or /+ +/.

On Mon, Oct 3, 2011 at 1:41 AM, Walter Bright
<newshound2 at digitalmars.com> wrote:
> On 10/2/2011 2:18 PM, Stewart Gordon wrote:
>>
>> Simply because we can't rely on every compiler to perform even the most
>> basic
>> cases of DCE?
>
> Consider:
>
>   if (a) { ... code ... }
>
> Sometimes, when debugging, I'll do:
>
>   if (0 && a) { ... code ... }
>
> to temporarily disable it. Should that be made illegal? If so, what about:
>
>   const X = 0;
>   if (X && a) { ... code ... }
>
> Illegal too? What about:
>
>   bool foo() { ... }
>   if (foo() && a) { ... code ... }
>
> where foo() may be evaluatable at compile time. How far should this go?
>


More information about the Digitalmars-d mailing list