Why do ints defined in template mixins have garbage values?
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Dec 11 21:17:46 UTC 2018
On Tue, Dec 11, 2018 at 09:09:55PM +0000, Johannes Riecken via Digitalmars-d-learn wrote:
> Code:
>
> import std.conv;
> import std.stdio;
>
> mixin template genInts()
> {
> enum arr = [0,1];
> static foreach (t; arr) {
> mixin("int i" ~ to!string(t) ~ " = 5;");
> }
> }
>
> void main() {
> mixin genInts!();
> writeln(i0);
> writeln(i1);
> }
>
>
> Expected output:
> 5
> 5
>
> Actual output is two garbage integer values.
Whoa. That looks like a compiler bug. File a bug here:
https://issues.dlang.org/enter_bug.cgi
T
--
There are two ways to write error-free programs; only the third one works.
More information about the Digitalmars-d-learn
mailing list