Bug 932 – static foreach in second template instantiation uses wrong tupleof
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-02-06T05:06:00Z
Last change time
2014-02-15T13:13:04Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
fvbommel
Comments
Comment #0 by fvbommel — 2007-02-06T05:06:09Z
---
void Fields(C)()
{
foreach(i, a; typeof(C.tupleof))
{
// fails for second instantiation:
// "test.d(7): static assert (is(int == real)) is false"
static assert(is(typeof(a) == typeof(C.tupleof)[i]));
}
}
struct MyStruct1 {
int afield;
}
struct MyStruct2 {
real afield;
}
void main() {
Fields!(MyStruct1);
Fields!(MyStruct2);
}
---
Reduced from code by Kyle Furlong, posted at http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.bugs&article_id=10262
I tested this on v1.00 and v1.002-v1.005, all fail above assert.
(keyword "wrong-code" because this causes wrong code generation, though with the static assert it of course doesn't compile. See the original example (at link above) for a program that compiles and produces wrong code)
This is an invalid bug. It fails because:
static assert(is( typeof(a)));
will always fail (a evaluates to 'int') inside a static foreach.
Correct code would be:
static assert(is(typeof(C.tupleof)[i] == a));
and that passes on DMD1.045 and 2.030.