www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7774] New: I've found a bug in D2

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7774

           Summary: I've found a bug in D2
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: vangelisforever yandex.ru



12:33:25 PDT ---
Try next code:

import std.stdio;

template TX(T)
{
struct A
{
    T x;
    T y;

    public void opOpAssign(string op)(double d)
    {
            debug writeln(op);
            if (op == "+")// +=
            {
                x += cast(T)d;
                y += cast(T)d;
            } else

            if (op == "-") // -=
            {
                x -= cast(T)d;
                y -= cast(T)d;
            } else
            if (op == "*") // *=
            {
                x *= cast(T)d;
                y *= cast(T)d; 
            } else
            if (op == "/") // /=
            {
                x /= cast(T)d;
                y /= cast(T)d; 
            } else 
            if (op == "%") // %=
            {
                x %= cast(T)d;
                y %= cast(T)d; 
            }
        }
    }
}
void main(string[] args)
{
       TX!(double).A a;
    a.x =10;
    a.y = 10;    
    a%=8.0;
    writeln(a.x, " ", a.y);    
}

You'll see that the a.x won't change. It must be 2 after %= operation.

Thank you.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 25 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7774


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com



12:59:59 PDT ---
I'm using your exact code, it works fine here on dmd2.059head win7 and prints 
2 2

Your version of dmd, system spec?

PS: I totally expected thouse ifs to be static ifs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7774


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



If confirmed this bug report needs a better name :-)


 PS: I totally expected thouse ifs to be static ifs.
Those variables are known at compile-time, so a good compiler is supposed to remove the useless if branches (quite probably dmd does it). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7774


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |timon.gehr gmx.ch
         Resolution|                            |WORKSFORME



You have found a bug in DMD 2.058, not in D2.


Smaller test case:
struct A{
    double x;
    void f(double d){x%=cast(double)d;}
}
void main(){
    auto a=A(10);
    a.f(8);
    assert(a.x!=10.0);
}

Works with DMD 2.059head, fails with DMD 2.058.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7774




23:46:44 PDT ---

 You have found a bug in DMD 2.058, not in D2.
 
 
 Smaller test case:
 struct A{
     double x;
     void f(double d){x%=cast(double)d;}
 }
 void main(){
     auto a=A(10);
     a.f(8);
     assert(a.x!=10.0);
 }
 
 Works with DMD 2.059head, fails with DMD 2.058.
How can I get a DMD 2.059 linux version or DMD 2.0? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 25 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7774





 
 How can I get a DMD 2.059 linux version or DMD 2.0?
It hasn't been released yet, but you can build it from source: https://github.com/D-Programming-Language/dmd -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 26 2012