Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!rex!uflorida!mephisto!mcnc!thorin!jason.cs.unc.edu!tuck From: tuck@jason.cs.unc.edu (Russ Tuck) Newsgroups: comp.lang.c++ Subject: user-defined conversion--bug or error? Keywords: user-defined conversion, cfront 2.0, g++ 1.36.1 Message-ID: <10986@thorin.cs.unc.edu> Date: 6 Dec 89 17:03:37 GMT Sender: news@thorin.cs.unc.edu Reply-To: tuck@jason.cs.unc.edu (Russ Tuck) Organization: University Of North Carolina, Chapel Hill Lines: 47 The example program below defines classes A and B. A has operator+, and B has a user-defined conversion to A. The question is whether it is legal to use A's + on B's objects, via the B->A conversion. GNU g++ 1.36.1 says yes, but AT&T cfront 2.0 says no. Which is right? I think the code is legal C++. Am I wrong? If so, please explain why. tuck@piglet> cat type2ab.C class A { public: friend const A operator+ (const A& lsrc, const A& rsrc); }; class B { public: B(); operator const A&(); }; main() { A a0; B b0, b1; a0 = b0 + b1; // legal??? } tuck@piglet> g++ -v -c type2ab.C gcc version 1.36.1 (based on GCC 1.36) /usr/softlab/contrib/lib/m68k_sunos/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -Dmc68010 type2ab.C /usr/tmp/cca07794.cpp GNU CPP version 1.36 /usr/softlab/contrib/lib/m68k_sunos/gcc-cc1plus /usr/tmp/cca07794.cpp -quiet -dumpbase type2ab.C -version -o /usr/tmp/cca07794.s GNU C++ version 1.36.1 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36. default target switches: /usr/softlab/contrib/lib/m68k_sunos/gcc-as -mc68010 -o type2ab.o /usr/tmp/cca07794.s tuck@piglet> CC.new -c type2ab.C CC type2ab.C: "type2ab.C", line 17: error: ambiguous use of overloaded +: B and B 1 error tuck@piglet> piglet is a Sun-3/60 running SunOS 4.0.3. Russ Tuck tuck@cs.unc.edu UNC Dept. of Computer Science ...!mcnc!unc!tuck CB 3175, Sitterson Hall Chapel Hill, NC 27599-3175, USA (919) 962-1755 or 962-1700