www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Bug in operator overloading!

reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
class A{}

void main ()
{
     A a,b;
     a=new A;
     b=new A;
     writefln(a==b);
     writefln(a<b);
     writefln(a+b);
     writefln(a-b);
     writefln(a*b); //'a' is not an arithmetic type
}

WHY? Why don't the first four writefln's couse error messages from
compiler!

I see it as a huge problem for generic programming!
For example: this template will work for the above A class
an any other class you write, even if you don't provide an opAdd
operator!

template func(Type)
{
    Type func(Type a, Type b)
    {
        return a+b;
     }
}
Aug 07 2004
parent Ben Hinkle <bhinkle4 juno.com> writes:
      writefln(a+b);
      writefln(a-b);
These two should error but do pointer arithmetic instead. That seems like a bug. The a==b and a<b are working as designed but by your post on the main newsgroup I think you'd like to see the design changed - which is different than the a+b and a-b examples.
Aug 07 2004