Bug 8256 – mixin() doesn't work in a template declaration

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-16T17:53:32Z
Last change time
2018-05-05T13:02:40Z
Assigned to
No Owner
Creator
dlang+issues

Comments

Comment #0 by dlang+issues — 2012-06-16T17:53:32Z
string getTypeName() { return "int"; } template Foo(T = mixin(getTypeName())) { }
Comment #1 by k.hara.pg — 2012-06-17T00:22:55Z
This is not allowed in current spec. http://dlang.org/expression.html#MixinExpression MixinExpression is an expression, not a type. template Foo(T = mixin(getTypeName())) { } ^ There should be a type. And the text contents of the string must be compilable as a valid AssignExpression.
Comment #2 by dlang+issues — 2012-06-17T01:37:22Z
Oh hmm, I see... any chance that it might be allowed at some point? :D
Comment #3 by k.hara.pg — 2012-06-17T02:05:15Z
Workaround(not tested): template Foo(T = typeof(mixin(getTypeName()).init)) { }
Comment #4 by dlang+issues — 2012-06-17T02:12:42Z
Oh cool, that works! Thanks!
Comment #5 by oli_r — 2018-05-05T13:02:40Z
I consider this solved. Please reopen if there is any implicit, actual request associated with this.