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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6084 - Impossible to instantiate local template with TypeTuple-foreach iterator variable.
Summary: Impossible to instantiate local template with TypeTuple-foreach iterator vari...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2011年06月01日 01:14 UTC by timon.gehr
Modified: 2011年09月25日 13:28 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011年06月01日 01:14:15 UTC
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 timon.gehr 2011年06月01日 01:31:07 UTC
Workaround:
import std.typetuple;
void main(){
 int foo(int x)(){return x;}
 foreach(_i;TypeTuple!(0)){
 enum i=_i;
 foo!i;
 }
}
Comment 2 timon.gehr 2011年06月01日 01:32:09 UTC
Another workaround:
import std.typetuple;
void main(){
 int foo(int x)(){return x;}
 foreach(i;TypeTuple!(0)){
 foo!(i+0);
 }
}
Comment 3 timon.gehr 2011年06月01日 01:59:17 UTC
patch:
In statement.c, ~line 1443:
- v->storage_class |= STCconst;
+ v->storage_class |= STCmanifest; // issue 6084 
Comment 4 Kenji Hara 2011年09月22日 11:41:43 UTC
https://github.com/D-Programming-Language/dmd/pull/406 


AltStyle によって変換されたページ (->オリジナル) /