Fixing spurious "statement is not reachable" in template code

tsbockman via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 27 09:05:29 PDT 2015


On Tuesday, 27 October 2015 at 13:23:51 UTC, Timon Gehr wrote:
> 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.

That's how the current implementation works, but that doesn't 
mean the warning is actually *helpful*.


More information about the Digitalmars-d mailing list