Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread Michelle Long via Digitalmars-d-learn
On Wednesday, 12 December 2018 at 16:33:02 UTC, H. S. Teoh wrote: On Wed, Dec 12, 2018 at 01:35:00PM +, AlCaponeJr via Digitalmars-d-learn wrote: On Tuesday, 11 December 2018 at 21:17:46 UTC, H. S. Teoh wrote: > Whoa. That looks like a compiler bug. File a bug here: > ... Genuinely asking

Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/18 10:22 AM, Kagamin wrote: On Tuesday, 11 December 2018 at 21:19:59 UTC, Steven Schveighoffer wrote: If I add an int using a regular declaration or a straight mixin("int i0 = 5;"); then the variable shows up. mixin template genInts() {     enum arr = [0];     static foreach (t;

Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 12, 2018 at 01:35:00PM +, AlCaponeJr via Digitalmars-d-learn wrote: > On Tuesday, 11 December 2018 at 21:17:46 UTC, H. S. Teoh wrote: > > Whoa. That looks like a compiler bug. File a bug here: > > ... > > Genuinely asking if this is a case of lacking of unit test for the >

Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 11 December 2018 at 21:19:59 UTC, Steven Schveighoffer wrote: If I add an int using a regular declaration or a straight mixin("int i0 = 5;"); then the variable shows up. mixin template genInts() { enum arr = [0]; static foreach (t; arr) { mixin("int i0 = 5;");

Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread AlCaponeJr via Digitalmars-d-learn
On Tuesday, 11 December 2018 at 21:17:46 UTC, H. S. Teoh wrote: Whoa. That looks like a compiler bug. File a bug here: ... Genuinely asking if this is a case of lacking of unit test for the Compiler or this is a case that where is hard to test or prevent? Al.

Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread Johannes Loher via Digitalmars-d-learn
On Tuesday, 11 December 2018 at 21:09:55 UTC, Johannes Riecken 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);

Re: Why do ints defined in template mixins have garbage values?

2018-12-11 Thread H. S. Teoh via Digitalmars-d-learn
P.S. Just looked at the disassembly. Seems to be a codegen bug -- the code appears to be trying to lookup local variables (presumably i0 and i1), but somehow the initialization code is missing. --T On Tue, Dec 11, 2018 at 09:09:55PM +, Johannes Riecken via Digitalmars-d-learn wrote: >

Re: Why do ints defined in template mixins have garbage values?

2018-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/11/18 4:09 PM, Johannes Riecken 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); }

Re: Why do ints defined in template mixins have garbage values?

2018-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 11, 2018 at 09:09:55PM +, 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

Why do ints defined in template mixins have garbage values?

2018-12-11 Thread Johannes Riecken via Digitalmars-d-learn
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