Topic: Overload resolution and initialization- compliers disagree


Author: "Rani Sharoni" <rani_sharoni@hotmail.com>
Date: 10 Jan 03 16:55:48 GMT
Raw View
Hello All:

I complied the following code with Comeau C/C++ 4.3.0.1, VC7.1 beta, BCC5.5
and GCC 3.2 (all in strict mode) and they seem to disagree:

template<typename T> struct D : T {};

struct A {
    A();
    A(A&);

    A(D<A>&);
    operator D<A>&();

    A(const D<A>&);
    operator const D<A>&() const;
};

A  f1();
const A f2() {
    const A x;
    return x; // case 1 - rejected by EDG, VC and BCC5.5
}

A x1 = f1(); // case 2 - rejected by GCC
A x2 = f2(); // case 3 - rejected by EDG

A  g1();
int g2(const A &);

int y = g2(g1()); // case 4 - rejected by EDG

Case 1:
EDG claimed that the call is ambiguous with candidates A(D<A> &) and A(D<A>
const&).
VC claimed that no copy constructor available
BCC5.5 claimed the same as EDG (but BCC5.6 accepted the code with strange
warning).

Case 2:
GCC claimed that the call is ambiguous with candidates A(A&), A(D<A> &) and
A(D<A> const&).

Case 3:
EDG claimed that the call is ambiguous with candidates A(D<A> &) and A(D<A>
const&).

Case 4:
EDG claimed "A::A(A &)", required for copy that was eliminated, is not
callable because reference parameter cannot be bound to rvalue

After reading 8.5/14 and 8.5.3/5/2/1 it seems to me that the above code is
legal especially since D<A> derived from A which makes all above the
initializations direct ones. If it is legal then it might be used for a
clean move semantics implementation.

Can anyone help me and clearly the legality of above cases?

Thanks,
Rani
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]