Fixing spurious "statement is not reachable" in template code
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue Oct 27 05:35:21 PDT 2015
On 10/27/15 3:50 AM, Daniel Murphy wrote:
> On 25/10/2015 4:25 AM, tsbockman wrote:
>> ///////////////////////////////
>> 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
>> }
>> ///////////////////////////////
>>
>
>
>>
>> Thoughts?
>
> Easy to fix:
>
> void reachIf(bool x)()
> {
> static if(!x)
> return;
> else
> writeln("reached");
> }
>
> The warning is correct, and incredibly annoying.
>
Easy to fix, but the warning is incorrect, the statement is reachable if
you use reachIf!true.
A statement is not a compiled piece of code.
-Steve
More information about the Digitalmars-d
mailing list