Fixing spurious "statement is not reachable" in template code
tsbockman via Digitalmars-d
digitalmars-d at puremagic.com
Tue Oct 27 13:18:50 PDT 2015
On Tuesday, 27 October 2015 at 19:30:08 UTC, Timon Gehr wrote:
> On 10/27/2015 06:35 PM, Steven Schveighoffer wrote:
>> I understand how the compiler treats it. In some cases, the
>> statement
>> is reachable, the compiler is unhelpfully pointing out cases
>> where it
>> was unreachable.
>
> The reachable statement is not the same as the statement that
> is flagged unreachable. This is not an implementation detail
> and it is not 'incorrect'. It might be changed if the consensus
> is that it is unhelpful. Personally, I usually avoid generating
> dead code.
I don't think any dead code is being generated, in the cases
where the compiler knows enough to issue the "statement is not
reachable" warning. My testing indicates that when the compiler
decides code is unreachable, it just removes it.
(I found this out because of a bug in the compiler:
http://forum.dlang.org/thread/qjmikijfluaniwnxhigp@forum.dlang.org)
Any fix for issue 14835 should still allow the compiler to detect
and remove dead code in template instantiations - but in cases
where the code could be reached with a different set of template
parameters, it should be removed silently, without the warning.
This would make it consistent with the behaviour of inlining, as
Steven Schveighoffer pointed out.
More information about the Digitalmars-d
mailing list