Bug 829 – struct operator overload returns a wrong value (suspect NRVO bug)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-01-11T02:37:00Z
Last change time
2014-02-15T13:13:00Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
timfang2006

Comments

Comment #0 by timfang2006 — 2007-01-11T02:37:35Z
The code below output is "nannannan".The code works properly in DMD 0.177 but fails in DMD 0.178 and 1.00. --code--------------------- import std.stdio; void main() { Vector3 a; a.set(1,1,1); a = a*2; writefln(a.x, a.y, a.z); } struct Vector3 { float x,y,z; // constructor void set(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } Vector3 opMul(float s) { Vector3 ret; ret.x = x*s; ret.y = y*s; ret.z = z*s; return ret; } }
Comment #1 by wbaxter — 2007-01-11T02:55:45Z
This appears to be a result of the NRVO added in DMD 0.178. The test program works fine with DMD 0.177, but fails with 0.178.
Comment #2 by lio+bugzilla — 2007-01-27T01:58:46Z
Fixed. Confirmed using dmd 1.004 on both linux and windows.
Comment #3 by thomas-dloop — 2007-02-15T03:42:46Z