static if enhancement

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 27 15:56:41 PDT 2016


On Monday, June 27, 2016 18:55:48 deadalnix via Digitalmars-d wrote:
> On Monday, 27 June 2016 at 18:14:26 UTC, Timon Gehr wrote:
> > Me, because that's what it means to evaluate the condition at
> > compile time and only compiling in the appropriate branch. This
> > is additional and special behaviour and it destroys the
> > orthogonality of 'static if' and 'return'. (I don't feel
> > strongly about the change, but the idea that the new behavior
> > should be expected anyway is flawed.)
>
> Alright, I have to range myself with most here. While I'm all for
> not warning about unreachable code, I'm opposed to not compiling
> the rest of the code. This create non orthogonality between
> static if and control flow analysis, the kind that clearly do not
> pay for itselfr

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



More information about the Digitalmars-d mailing list