Bug 6084 – Impossible to instantiate local template with TypeTuple-foreach iterator variable.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-01T01:14:00Z
Last change time
2011-09-25T13:28:49Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-06-01T01:14:15Z
The following code is rejected by DMD: import std.typetuple; void main(){ int foo(int x)(){return x;} foreach(i;TypeTuple!(0)) foo!(i); } Error: template instance cannot use local 'i' as parameter to non-global template foo(int x) 'i' is only a compile-time constant integral value at the point of instantiation, therefore there is no reason why this should not work.
Comment #1 by timon.gehr — 2011-06-01T01:31:07Z
Workaround: import std.typetuple; void main(){ int foo(int x)(){return x;} foreach(_i;TypeTuple!(0)){ enum i=_i; foo!i; } }
Comment #2 by timon.gehr — 2011-06-01T01:32:09Z
Another workaround: import std.typetuple; void main(){ int foo(int x)(){return x;} foreach(i;TypeTuple!(0)){ foo!(i+0); } }
Comment #3 by timon.gehr — 2011-06-01T01:59:17Z
patch: In statement.c, ~line 1443: - v->storage_class |= STCconst; + v->storage_class |= STCmanifest; // issue 6084
Comment #4 by k.hara.pg — 2011-09-22T11:41:43Z
Comment #5 by bugzilla — 2011-09-25T13:28:49Z