Thread overview
[Issue 829] New: struct operator opMul() return a wrong value
Jan 11, 2007
d-bugmail
[Issue 829] struct operator overload returns a wrong value (suspect NRVO bug)
Jan 11, 2007
d-bugmail
Jan 27, 2007
d-bugmail
Feb 15, 2007
d-bugmail
January 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=829

           Summary: struct operator opMul() return a wrong value
           Product: D
           Version: 1.00
          Platform: PC
               URL: http://www.digitalmars.com/pnews/read.php?server=news.di
                    gitalmars.com&group=digitalmars.D&artnum=46576
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: timfang2006@126.com


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;
 }
}


-- 

January 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=829


wbaxter@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|struct operator opMul()     |struct operator overload
                   |return a wrong value        |returns a wrong value
                   |                            |(suspect NRVO bug)




------- Comment #1 from wbaxter@gmail.com  2007-01-11 02:55 -------
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.


-- 

January 27, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=829


lio@lunesu.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from lio@lunesu.com  2007-01-27 01:58 -------
Fixed. Confirmed using dmd 1.004 on both linux and windows.


-- 

February 15, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=829





------- Comment #3 from thomas-dloop@kuehne.cn  2007-02-15 03:42 -------
Added to DStress as http://dstress.kuehne.cn/run/s/struct_27_B.d http://dstress.kuehne.cn/run/s/struct_27_C.d


--