Spurious compiler warning ?

Don nospam at nospam.com
Thu Nov 3 01:15:28 PDT 2011


On 03.11.2011 08:47, knommad wrote:
> Hi,
>
> I'm a relative newcomer to D, and am enjoying the experience.
>
> I have a small testcase here that causes what seems to be a spurious warning
> from the compiler (resulting code still works, however).
>
> Am I missing something??

It's an interesting situation that you've found. The foreach is a static 
foreach, so it gets unrolled at compile time. In each unrolled bit, 
'member' is a compile-time constant, so the if statement becomes either 
true or false. The code is in fact unreachable in that iteration.
So the warning is correct, but arguably not helpful.

Maybe we should suppress unreachable code warnings inside unrolled code.


More information about the Digitalmars-d mailing list