Fixing spurious "statement is not reachable" in template code

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 27 06:23:50 PDT 2015


On 10/27/2015 01:35 PM, Steven Schveighoffer wrote:
>>
>> 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

Versions of the same statement in different instantiations are 
independent. Templates are just a restricted form of hygienic macros.



More information about the Digitalmars-d mailing list