static if enhancement

QAston via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 28 06:34:48 PDT 2016


On Monday, 27 June 2016 at 22:56:41 UTC, Jonathan M Davis wrote:
> Agreed. The code outside of the static if should be compiled 
> regardless, because it's not part of the static if/else at all 
> and therefore has not been marked as conditionally compilable. 
> But if we don't warn about unreachable code, then the code 
> after the static if can clearly be optimized out because it's 
> unreachable. So, Andrei's code would become legal as long as 
> the only problem with the code after the static if was that it 
> was unreachable.
>
> - Jonathan M Davis

The "allow unreachable code" solution has it's own limitations 
compared to implicit-else-block. It doesn't allow varying return 
type and differing declarations in the two blocks.

Allowing unreachable code also shares readibility problems 
(because the example code is exactly the same for both 
solutions), although it's conceptually easier to understand and 
more consistent, so it's prefered.

I personally like present state of things.


More information about the Digitalmars-d mailing list