Topic: Question about -fansi-overloading, g++


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Wed, 16 Feb 1994 04:24:47 GMT
Raw View
pierre@CIM.McGill.CA (Pierre P. Tremblay) writes:

>We're having trouble understanding the following, compiled with g++
>with the -fansi-overloading flag.  The compiler does not complain if
>the flag is removed.  I'll be delighted to read the appropriate
>section of the ARM if that's where the problem is ;)

It looks like a compiler bug to me.
I'm cross-posting to comp.std.c++.

>Send me mail if you've already figured this one out.
>----------------------------------------------------------------------
>class Z
>{
>public:
>  void operator+(double);
>};
>
>class X { };
>
>class Y : public X
>{
>public:
>  Y();
>  Y(const Y&);
>};
>
>void operator+(Z, const X&);
>void operator+(Z, const Y&);
>
>void foo()
>{
>  Z z;
>  X x;
>  Y y;
>
>  operator+(z, x);    // Ok
>  operator+(z, y);    // Ok
>
>  z + x;              // Ok
>  z + 2.0;            // Ok
>  z + y;              // Error
>  // The last line generates the following error with -fansi-overloading flag:
>  // "aga.cc:32: type conversion required for binary operation on types `Z' and `Y'"
>
>  z + (const X&)y;    // Ok
>  z + (const Y&)y;    // Ok
>}

operator+(Z, const Y&) is an "exact match" (only trivial conversions
required) on both arguments for the call `z + y'.  The other two
operator+() functions in scope both require a conversion (well,
one doesn't match at all).  So it would seem that the call should
be unambiguous.

--
Fergus Henderson - fjh@munta.cs.mu.oz.au