The following code doesn't make sense to me, yet DMD accepts it: module k; enum TYP { ch, c } class TypeBasic { int oo; /// Allocates an instance of TypeBasic and assigns it to typeName. template newTB(char[] typeName) { const newTB = mixin("new TypeBasic(TYP."~typeName~")"); } /// Initializes predefined types. static this() { newTB!("c"); newTB!("ch"); } this(int inp) { oo=inp; } } void main() { } I got this from a LDC bug report in IRC, and TBH I can't think anything but WTF is going on here? DMD seems to emit two 'new' expressions in the static ctor. I would think it should be: error: 'new TypeBasic(TYP.c)' is not a constant expression
Anoter test case: template newTB(char[] a, char[] b) { const newTB = mixin(a~"+"~b); } void main() { int a, b; auto c = newTB!("a", "b"); } Here the bogus error message: Error: Array operations not implemented is produced when it should be: Error: a + b is not a constant expression. or am I completely off here ?
Ok the second one makes a little sense. but what about this one: template newTB(char[] c, char[] d) { const newTB = mixin(c~"+"~d); } int a=1, b=2; void main() { auto c = newTB!("a", "b"); printf("%d\n", c); a = 4; b = 6; c = newTB!("a", "b"); printf("%d\n", c); } extern(C) int printf(char*, ...); /* [tomas@myhost tests]$ dmd bar.d [tomas@myhost tests]$ ./bar 3 10 */ ?
Updated test case for D2.052: template newTB(string c, string d) { enum newTB = mixin(c~"+"~d); } int a=1, b=2; void main() { auto c = newTB!("a", "b"); a = 4; b = 6; c = newTB!("a", "b"); }
*** This issue has been marked as a duplicate of issue 2526 ***