[Issue 14243] New: mixin template scope inconsistency?
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Mar 3 22:22:19 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14243
Issue ID: 14243
Summary: mixin template scope inconsistency?
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: blocker
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: timothee.cour2 at gmail.com
[reposted from EMAIL:mixin template scope inconsistency? in
digitalmars-d-learn at puremagic.com]
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
----------------
--
More information about the Digitalmars-d-bugs
mailing list