www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Bug related to operators and namespaces

Hi,


The code below is rejected by version 8.48 of the Digital Mars compiler; it is
accepted by Borland, Visual and Comeau and (most important) it looks valid to me
:)

Maybe the definition of operator+ should be searched for in the current
namespace too, not only in the namespaces of the operands...



----------------------------------------------------- Cut here
namespace N1
{
class X { int _i; };
}

namespace N2
{
N1::X operator+ (const N1::X &x1, const N1::X &x2)
{ return x1; }

void Test ()
{
N1::X x;
operator+ (x, x); // works
x + x;            // fails
}
}

int main ()
{ return 0; }
----------------------------------------------------- and here


The error message is:

x + x;
^
main.cpp(22) : Error: illegal operand types
Had: N1::X
and: N1::X



--
Yours truly,
Adder
Jul 16 2006