www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 829] New: struct operator opMul() return a wrong value

reply d-bugmail puremagic.com writes:
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;
 }
}


-- 
Jan 11 2007
next sibling parent d-bugmail puremagic.com writes:
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)





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.


-- 
Jan 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=829


lio lunesu.com changed:

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





Fixed. Confirmed using dmd 1.004 on both linux and windows.


-- 
Jan 26 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=829






Added to DStress as
http://dstress.kuehne.cn/run/s/struct_27_B.d
http://dstress.kuehne.cn/run/s/struct_27_C.d


-- 
Feb 15 2007