<html>
<head>
<base href="http://bugzilla.gdcproject.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - invalid code generation with -O2 for method returning ref"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=179">179</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>invalid code generation with -O2 for method returning ref
</td>
</tr>
<tr>
<th>Product</th>
<td>GDC
</td>
</tr>
<tr>
<th>Version</th>
<td>4.9.x
</td>
</tr>
<tr>
<th>Hardware</th>
<td>x86
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>Normal
</td>
</tr>
<tr>
<th>Component</th>
<td>gdc
</td>
</tr>
<tr>
<th>Assignee</th>
<td>ibuclaw@gdcproject.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ketmar@ketmar.no-ip.org
</td>
</tr></table>
<p>
<div>
<pre>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);
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are watching all bug changes.</li>
</ul>
</body>
</html>