[Bug 179] New: invalid code generation with -O2 for method returning ref
via D.gnu
d.gnu at puremagic.com
Fri Apr 17 10:18:01 PDT 2015
http://bugzilla.gdcproject.org/show_bug.cgi?id=179
Bug ID: 179
Summary: invalid code generation with -O2 for method returning
ref
Product: GDC
Version: 4.9.x
Hardware: x86
OS: Linux
Status: NEW
Severity: normal
Priority: Normal
Component: gdc
Assignee: ibuclaw at gdcproject.org
Reporter: ketmar at ketmar.no-ip.org
the following code works with -O0, but segfaults with -O2.
the expected output (-O0 is ok):
emit: me=B743FFF8
addS: me=B743FFF8
output with -O2:
emit: me=B73ECFF8
addS: me=BFAC86B8
the thing is that both addresses MUST be the same, and they are with -O0. but
with -O2 second address is completely wrong.
this works:
# gdc -o z00_gdc -O0 z00.d && ./z00_gdc
and this segfaults:
# gdc -o z00_gdc -O2 z00.d && ./z00_gdc
the code:
=== z00.d ===
import std.stdio;
struct Signal(Args...) {
private:
RestrictedSignal!(Args) mRestricted;
public:
alias restricted this;
void emit (Args args) @trusted { mRestricted.mImpl.emit(args); }
@property ref RestrictedSignal!(Args) restricted () @trusted { return
mRestricted; }
}
struct RestrictedSignal(Args...) {
private:
SignalImpl mImpl;
public:
void connect(string method, ClassType) (ClassType obj) @trusted
//if (is(ClassType == class) && __traits(compiles, {void delegate (Args) dg =
mixin("&obj."~method);}))
{
mImpl.addSlot(obj, cast(void delegate ())mixin("&obj."~method));
}
}
private struct SignalImpl {
@disable this (this);
@disable void opAssign (SignalImpl other);
void emit(Args...) (Args args) {
writeln("emit: me=", &this);
}
void addSlot (Object obj, void delegate () dg) {
writeln("addS: me=", &this);
}
}
class MyObject {
ref RestrictedSignal!(string, int) valueChanged () { return valueChangedSg; }
private Signal!(string, int) valueChangedSg;
@property void value (int v) {
valueChangedSg.emit("setting new value", v);
}
}
class Observer {
void watch (string msg, int i) {}
}
void main () {
auto a = new MyObject;
auto o = new Observer;
a.value = 3;
a.valueChanged.connect!"watch"(o);
}
--
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20150417/9eec7c03/attachment.html>
More information about the D.gnu
mailing list