Bug 14243 – mixin template scope inconsistency?

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-04T06:22:00Z
Last change time
2015-06-17T21:04:34Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
timothee.cour2

Comments

Comment #0 by timothee.cour2 — 2015-03-04T06:22:19Z
[reposted from EMAIL:mixin template scope inconsistency? in [email protected]] Template mixin scope seems to have a weird behavior: I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. import std.stdio; struct A{ int b; this(int b){ this.b=b; writeln("A.begin"); } ~this(){ writeln("A.end"); } } mixin template Entry(){ auto a=A(12); } void test1(){ writeln("test.begin"); mixin Entry; writeln(a.b);//WEIRD! destructor has been called but a.b is still alive writeln("test.end"); } void test2(){ writeln("test.begin"); auto a=A(0); writeln("test.end"); } void test3(){ writeln("test.begin"); mixin("auto a=A(0);"); writeln("test.end"); } void main(){ test1; writeln; test2; writeln; test3; } output: ---------------- test.begin A.begin A.end //WEIRD(1): why is destructor called before test.end? 12 //WEIRD(2): destructor has been called but a.b is still alive test.end test.begin A.begin test.end A.end test.begin A.begin test.end A.end ----------------
Comment #1 by k.hara.pg — 2015-03-05T16:06:46Z
Comment #2 by github-bugzilla — 2015-04-09T02:05:23Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f54862eb0e4a9af4265042f35972bf6e91d1eaf1 fix Issue 14243 - mixin template scope inconsistency? https://github.com/D-Programming-Language/dmd/commit/50b19975fdb339c56c3c96f7e5e706b9090eebbe Merge pull request #4455 from 9rnsr/fix14243 Issue 14243 - mixin template scope inconsistency?
Comment #3 by github-bugzilla — 2015-06-17T21:04:34Z