Bug 6312 – template instance cannot use argument from enclosing template

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-14T04:16:00Z
Last change time
2015-06-09T05:11:47Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
hoganmeier

Comments

Comment #0 by hoganmeier — 2011-07-14T04:16:39Z
extern(C) void printf(const char*, ...); void h() { printf("h()"); } class Bla { mixin wrap!h; } mixin template wrap(alias f) { void blub(alias g = f)() { g(); } } void main() { Bla b = new Bla(); b.blub(); } $ dmd -c nonlocaltemplate.d nonlocaltemplate.d(20): Error: template instance cannot use local 'f' as parameter to non-global template blub(alias g = f) nonlocaltemplate.d(20): Error: template instance forward reference of f nonlocaltemplate.d(20): Error: template instance nonlocaltemplate.Bla.wrap!(h).blub!(f) error instantiating Note that imho this is different from http://d.puremagic.com/issues/show_bug.cgi?id=3051 because here the argument is not on the stack but it's a template argument (and thus a compile-time value)
Comment #1 by hoganmeier — 2011-11-11T08:24:41Z
Ok, here's a real ugly workaround: extern(C) void printf(const char*, ...); void h() { printf("h()"); } class Bla { mixin wrap!h; } private enum dummy {foo} mixin template wrap(alias f) { void blub(alias h = dummy)() { static if (is (h == enum)) alias f g; else alias h g; g(); } } void main() { Bla b = new Bla(); b.blub(); }
Comment #2 by k.hara.pg — 2013-04-06T02:18:06Z
Comment #3 by github-bugzilla — 2013-04-06T18:47:06Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/db5e6087a2ed742bb0ce024dc5154075cd54df43 fix Issue 6312 - template instance cannot use argument from enclosing template https://github.com/D-Programming-Language/dmd/commit/f946ede5e9b597c6e32c1e66b311460204532cd9 Merge pull request #1850 from 9rnsr/fix6312 Issue 6312 - template instance cannot use argument from enclosing template