Is this a bug?
Robert Clipsham
robert at octarineparrot.com
Fri Apr 20 12:21:12 PDT 2012
I've been staring blankly at this for a while now and want some input
from others:
----
void foo(T, U...)(bool arg)
{
if (arg)
{
assert(T.tupleof.length == U.length);
assert(arg); /* Line 6 */
// Or some other code here
}
}
struct A {}
void main()
{
foo!(A, int)(false);
}
----
When compiled with warnings:
$ dmd -w test.d
test.d(6): Warning: statement is not reachable
So what appears to be happening here is that dmd is constant folding
T.tupleof.length == U.length to false, then assert(arg) can never
happen, so the warning is given.
It is obvious, however, that the assertion will never be executed
anyway. Has anyone else run into this situation? The compile time
parameters only need to match based on the runtime value provided (other
branches in the code don't have such strict requirements for the compile
time parameters).
Is there some way around this? (other than compiling without -w)
I can't help but feel what I'm doing isn't right some how.
Apologies if this makes no sense, I'm rather tired.
--
Robert
http://octarineparrot.com/
More information about the Digitalmars-d
mailing list