From 4803161280099104803
X-Google-Thread: f78e5,8983dbb7c598f774
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 30 Jul 2006 19:10:04 -0500
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
From: "Greg Herlihy" <greghe@pacbell.net>
Newsgroups: comp.std.c++
Subject: Re: Ambiguous conversion to base?
Organization: http://groups.google.com
Message-ID: <1154303691.576895.287710@s13g2000cwa.googlegroups.com>
References: <eag3it$5qn$1$8302bc10@news.demon.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: s13g2000cwa.googlegroups.com; posting-host=71.141.225.205;
   posting-account=JdllFQ0AAAC-QghphnHMZz5q0GHnzGUJ
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Date: Sun, 30 Jul 2006 19:08:32 CST
Lines: 65
NNTP-Posting-Host: 65.182.171.162
X-Trace: sv3-lJ08VdoSCX+5GNxVfdL7Ek1FyQn57zG3xw63ZOS4f7Voy5npERFomhijUWjnoBiuEOpoDVGZARSqx25!jw6CvCBSoXaYCRs6LBsXhiNvQGalFlV1tmjVtyBv5mtmhFXpX47CMDAdKy7KK8PHTrxaT22fu4w8!eboGyZFrAEMlt+VpyT3wo9Qdtba4GYEuV2J/nnX+x6I=
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: abuse@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: g2news2.google.com comp.std.c++:3148

"Roger Orr" wrote:
> Should this fragment compile?
>
> class Base
> {
> };
>
> class Derived : public Base
> {
> public:
>    Derived( Derived const & );
>    Derived( Base const ); // Note: no '&'
> };
>
> class Final : public Derived
> {
>    Final( Final const & f )
>    : Derived( f ) {}
> };
>
> MSVC 2003 and Comeau say 'Yes'
> g++ 3.4.4 and 4.0.2 say 'No':
>
> copyctor.cpp: In copy constructor `Final::Final(const Final&)':
> copyctor.cpp:15: error: call of overloaded `Derived(const Final&)' is
> ambiguous
> copyctor.cpp:9: note: candidates are: Derived::Derived(Base)
> copyctor.cpp:8: note:  Derived::Derived(const Derived&)
>
> As far as I understand it conversion from Final const & -> Derived const &
> should be a better conversion than any conversion to Base.
> Or have I missed something?

I would vote with gcc - the call Derived( f ) does indeed appear to be
ambiguous. The two eligible functions Derived(Base) and Derived(const
Derived&) both require a derived-to-base conversion for the argument.
Therefore both functions are awarded Conversion rank.

Now, the "distance" of a derived-to-base conversion can often serve a
tiebreaker when deciding between two derived-to-base conversions. The
compiler will favor more "immediate" conversions (such as the one-hop
Final to Derived conversion) over those farther apart in the class
hierarchy (such as the two-hop Final to Base conversion). But the
compiler can apply this tiebreaker only when the parameters requiring
the conversions are both references, both pointers or both values. In
this case, one parameter is a reference and the other is a value. Since
the parameters do not agree in form, the tiebreaker never gets to be
excercised. The call to Derived remains ambiguous. (Note that changing
the parameters to be both references, both values or both pointers
resolves the ambiguity).

Moreover, an error seems the most appropriate outcome in this
situation. After all, whether to call a function with a value parameter
or with a reference parameter is a more important decision (and one
which the compiler wisely refrains from making itself) than which
derived-to-base class conversion is preferable. 

Greg

---
[ 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.comeaucomputing.com/csc/faq.html                      ]



