Fixing spurious "statement is not reachable" in template code
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Tue Oct 27 14:33:02 PDT 2015
On Saturday, 24 October 2015 at 17:25:23 UTC, tsbockman wrote:
> While improving the DMD front-end's constant folding:
> https://github.com/D-Programming-Language/dmd/pull/5229
> I found out about DMD issue 14835:
> https://issues.dlang.org/show_bug.cgi?id=14835
>
> Briefly:
> ///////////////////////////////
> module main;
>
> import std.stdio;
>
> void reachIf(bool x)()
> {
> if(!x)
> return;
> writeln("reached"); // Warning: statement is not reachable
> }
>
> void main(string[] args) {
> reachIf!true(); // prints "reached"
> reachIf!false(); // triggers warning
> }
> ///////////////////////////////
>
> This is, I think, a big problem.
It is. This is the optimizer leaking into semantic. As far as
language definition is concerned, this is a runtime if and
changing it to a compile time one is an optimization.
If this was a static if, then generating a error is reasonable,
but with a regular if, it isn't.
More information about the Digitalmars-d
mailing list