Topic: Overloading Ambiguity?
Author: markw65@my-deja.com (Mark Williams)
Date: Mon, 13 Aug 2001 22:14:38 GMT Raw View
Francis Glassborow <francis.glassborow@ntlworld.com> wrote in message news:<EppEWRBXJqd7Ew$P@ntlworld.com>...
> >> > struct A1 {};
> >> > struct A2 {};
> >> >
> >> > struct B1 : A1 {};
> >> > struct B2 : A1 {};
> >> > struct B3 : A2 {};
> >> >
> >> > struct C : B1, B2, B3 {};
> >> >
> >> > void foo(const A1&);
> >> > void foo(condt A2&);
> >> >
> >> > void foo func(const C &c) { foo(c); }
> >> >
> >> > gcc and vc complained about ambiguity.
>
> Any compiler that makes a choice is wrong. the parameter func has
> equally viable conversions to A1 and A2 so how do you think it should
> choose? By tossing a coin?
No. By the rules of the standard, as stated by the OP:
>> 13.3 -- 3
>> --Then the best viable function is selected based on the implicit
conversion
>> sequences (_over.best.ics_) needed to match ...
>> 4 -- 3
>> An expression e can be implicitly converted to a type T if and only
if the
>> declaration ?T t=e;" is well-formed, ...
Given an expression c of type C, the declaration "A1 t = c;" is not
well formed, so there is no implicit conversion from C to A1, so
foo(const A1 &) is not a viable function, so the compiler *must*
choose foo(const A2 &).
> Now you have a second ambiguity in the case
> of A1, because C has two A1 subobjects, but the existence of that does
> not mean that the compiler should choose the lesser ambiguity and go for
> A2.
Which seems to be in direct contradiction of the standard. Can you
support your position?
Mark Williams
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Tue, 14 Aug 2001 00:47:08 GMT Raw View
In article <10f784d5.0108131310.621c7a3e@posting.google.com>, Mark
Williams <markw65@my-deja.com> writes
>Given an expression c of type C, the declaration "A1 t = c;" is not
>well formed, so there is no implicit conversion from C to A1, so
>foo(const A1 &) is not a viable function, so the compiler *must*
>choose foo(const A2 &).
>
>> Now you have a second ambiguity in the case
>> of A1, because C has two A1 subobjects, but the existence of that does
>> not mean that the compiler should choose the lesser ambiguity and go for
>> A2.
>
>Which seems to be in direct contradiction of the standard. Can you
>support your position?
13.3.3.1 para 10 refers to ambiguous conversion sequences.
If 4 para 3 applied then we would not be able to have ambiguous
conversion sequences because in all such cases the specified declaration
would be ill-formed.
I think this is a defect in the Standard, that should be corrected by
finding wording to make the case we are discussing ambiguous. While I
understand the interpretation of the OP, I find it hard to believe that
we would actually want code to be have that way.
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: sadprozac@yahoo.com (Rani Sharoni)
Date: Sun, 12 Aug 2001 13:26:48 GMT Raw View
Sorry but I made a mistake, Bcc choose "void foo(const A2&)".
So can anyone tell if "void foo(const A1&)" is a viable function?
Thanks,
Rani
jk@steel.orel.ru (Eugene Karpachov) wrote in message news:<slrn9lshih.g9.jk@localhost.localdomain>...
> Tue, 24 Jul 2001 17:18:46 GMT Rani Sharoni :
> > struct A1 {};
> > struct A2 {};
> >
> > struct B1 : A1 {};
> > struct B2 : A1 {};
> > struct B3 : A2 {};
> >
> > struct C : B1, B2, B3 {};
> >
> > void foo(const A1&);
> > void foo(condt A2&);
> >
> > void foo func(const C &c) { foo(c); }
> >
> > gcc and vc complained about ambiguity.
>
> They are right.
>
> > Bcc choose the foo(const A1&) function.
correction: Bcc choose the foo(const A2&) function.
>
> For which "const A1&"? Was it
> void foo func(const C &c) { foo( static cast<const B1 &>(c) ); }
>
> or
>
> void foo func(const C &c) { foo( static cast<const B2 &>(c) ); }?
>
>
> >So it seems that the borland compiler is right because the expression "c
> onst
> ^^^^^
> Do you mean "wrong"?
>
> >A1 &t=c" is ill-formed making void foo(const A1&) not viable, but I'm
> not
> >sure.
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Mon, 13 Aug 2001 03:26:48 GMT Raw View
In article <f1395bf8.0108112352.5f13b73b@posting.google.com>, Rani
Sharoni <sadprozac@yahoo.com> writes
>Sorry but I made a mistake, Bcc choose "void foo(const A2&)".
>So can anyone tell if "void foo(const A1&)" is a viable function?
>
>Thanks,
>Rani
>
>jk@steel.orel.ru (Eugene Karpachov) wrote in message news:<slrn9lshih.g9=
.jk@loca
>lhost.localdomain>...
>> Tue, 24 Jul 2001 17:18:46 GMT Rani Sharoni =CE=C1=D0=C9=D3=C1=CC:
>> > struct A1 {};
>> > struct A2 {};
>> >
>> > struct B1 : A1 {};
>> > struct B2 : A1 {};
>> > struct B3 : A2 {};
>> >
>> > struct C : B1, B2, B3 {};
>> >
>> > void foo(const A1&);
>> > void foo(condt A2&);
>> >
>> > void foo func(const C &c) { foo(c); }
>> >
>> > gcc and vc complained about ambiguity.
Any compiler that makes a choice is wrong. the parameter func has
equally viable conversions to A1 and A2 so how do you think it should
choose? By tossing a coin? Now you have a second ambiguity in the case
of A1, because C has two A1 subobjects, but the existence of that does
not mean that the compiler should choose the lesser ambiguity and go for
A2.
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: "Rani Sharoni" <s3173243@techst02.technion.ac.il>
Date: Tue, 24 Jul 2001 17:18:46 GMT Raw View
Hello All:
I recently faced the some code that I can't compile with gcc 3.0
(online) and vc7 (beta 2) but I can with bcc 5.5
I compiled the following code:
struct A1 {};
struct A2 {};
struct B1 : A1 {};
struct B2 : A1 {};
struct B3 : A2 {};
struct C : B1, B2, B3 {};
void foo(const A1&);
void foo(condt A2&);
void foo_func(const C &c) { foo(c); }
gcc and vc complained about ambiguity.
Bcc choose the foo(const A1&) function.
I noticed that the standard says (4 3 and 13.3 3):
13.3 -- 3
--Then the best viable function is selected based on the implicit conversion
sequences (_over.best.ics_) needed to match ...
4 -- 3
An expression e can be implicitly converted to a type T if and only if the
declaration T t=e;" is well-formed, ...
So it seems that the borland compiler is right because the expression "const
A1 &t=c" is ill-formed making void foo(const A1&) not viable, but I'm not
sure.
Can anyone say if the code is legal?
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: jk@steel.orel.ru (Eugene Karpachov)
Date: Wed, 25 Jul 2001 04:41:21 GMT Raw View
Tue, 24 Jul 2001 17:18:46 GMT Rani Sharoni =CE=C1=D0=C9=D3=C1=CC:
> struct A1 {};
> struct A2 {};
>
> struct B1 : A1 {};
> struct B2 : A1 {};
> struct B3 : A2 {};
>
> struct C : B1, B2, B3 {};
>
> void foo(const A1&);
> void foo(condt A2&);
>
> void foo_func(const C &c) { foo(c); }
>
> gcc and vc complained about ambiguity.
They are right.
> Bcc choose the foo(const A1&) function.
For which "const A1&"? Was it=20
void foo_func(const C &c) { foo( static_cast<const B1 &>(c) ); }
or =20
=20
void foo_func(const C &c) { foo( static_cast<const B2 &>(c) ); }?
>So it seems that the borland compiler is right because the expression "c=
onst
^^^^^
Do you mean "wrong"?
>A1 &t=3Dc" is ill-formed making void foo(const A1&) not viable, but I'm =
not
>sure.
--=20
jk
---
[ 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.research.att.com/~austern/csc/faq.html ]