Bug 1036 – regression: invalid code generation for class literal expression unless -fPIC or -release is used

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-03-07T17:08:00Z
Last change time
2015-06-09T05:14:41Z
Assigned to
dvdfrdmn
Creator
thomas-dloop

Comments

Comment #0 by thomas-dloop — 2007-03-07T17:08:13Z
# int main(){ # int status; # # int delegate() foo(){ # return &(new class # { # int dg(){ # return ++status; # } # } # ).dg; # } # # int delegate() bar = foo(); # # if(status != 0){ # assert(0); # } # # if(bar() != 1){ # assert(0); # } # # if(status != 1){ # assert(0); # } # # return 0; # } gdmd-0.23 run/c/class_26_B.d -ofx && ./x -> Error: AssertError Failure run/c/class_26_B.d(32) gdmd-0.23 run/c/class_26_B.d -fPIC -ofx && ./x -> success test case: http://dstress.kuehne.cn/run/c/class_26_B.d
Comment #1 by dvdfrdmn — 2007-03-11T08:13:44Z
Exiting from 'foo' invalidates the anonymous class' link to 'status'. The correct way to do this is to have a direct pointer to the outer stack frame: return &(new class { int *p_status; this() { p_status = & status; } int dg() { return ++ *p_status; } } ).dg;
Comment #2 by thomas-dloop — 2007-03-12T00:31:52Z
Thanks, fixed