egcs-1.0.1 confused by explicit cast

Richard Hadsell hadsell@blueskystudios.com
Fri Jan 23 11:03:00 GMT 1998


It seems that an explicit cast can confuse the compiler into attempting
some other conversion sequence.  Here is the test case:

loki1 studio++/tests 68% cat egcsbug3.cc 
class A {
public:
        A (double a);
};

class B {
public:
        operator double () const;
        operator A () const;
};

class C {
public:
        void    f (A& a, const B& b) const;
};

void    C::f (A& a, const B& b) const
{
        a = b.operator A ();    // o.k.
        a = b;                  // o.k.
        a = (A) b;              // compiler complains
}
loki1 studio++/tests 69% ECC -v -c egcsbug3.cc 
Reading specs from
/usr/local/lib/gcc-lib/alphaev5-unknown-linux-gnu/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)
 /usr/local/lib/gcc-lib/alphaev5-unknown-linux-gnu/egcs-2.90.23/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
-D__GNUC_MINOR__=90 -D__alpha -D__alpha__ -D__linux__ -D__linux
-D_LONGLONG -Dlinux -Dunix -D__ELF__ -D__alpha -D__alpha__ -D__linux__
-D__linux -D_LONGLONG -D__linux__ -D__unix__ -D__ELF__ -D__linux
-D__unix -Asystem(linux) -Acpu(alpha) -Amachine(alpha) -D__EXCEPTIONS
-D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C -D__LANGUAGE_C_PLUS_PLUS__
-D__LANGUAGE_C_PLUS_PLUS -D__cplusplus egcsbug3.cc /tmp/cca09741.ii
GNU CPP version egcs-2.90.23 980102 (egcs-1.0.1 release) (Alpha
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++
 /usr/local/include
 /usr/local/alphaev5-unknown-linux-gnu/include
 /usr/local/lib/gcc-lib/alphaev5-unknown-linux-gnu/egcs-2.90.23/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/alphaev5-unknown-linux-gnu/egcs-2.90.23/cc1plus
/tmp/cca09741.ii -quiet -dumpbase egcsbug3.cc -version -o
/tmp/cca09741.s
GNU C++ version egcs-2.90.23 980102 (egcs-1.0.1 release)
(alphaev5-unknown-linux-gnu) compiled by GNU C version egcs-2.90.23
980102 (egcs-1.0.1 release).
egcsbug3.cc: In method `void C::f(class A &, const class B &) const':
egcsbug3.cc:21: call of overloaded `A(const B &)' is ambiguous
egcsbug3.cc:4: candidates are: A::A(const A &)
egcsbug3.cc:3:                 A::A(double)
loki1 studio++/tests 70%

The implicit conversion required by the simple assignment "a = b;"
succeeds, probably because it is not allowed to use more than one
user-defined conversion in an implicit conversion sequence.  The
compiler has to choose B::operator A(), because there is no A::A(const B
&).  But the explicit cast to A seems to trick the compiler into looking
for an implicit conversion in addition.  I can't tell whether that would
be added to the sequence before or after the explicit cast, because
neither one makes sense.

-- 
Dick Hadsell			914-381-8400  Fax: 914-381-9790
Reply-to:			hadsell@blueskystudios.com
Blue Sky | VIFX			http://www.blueskystudios.com
1 South Road, Harrison, NY 10528



More information about the Gcc-bugs mailing list