Topic: Overload resolution -best viable function
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1998/06/13 Raw View
James Kuyper <kuyper@wizard.net> writes:
|> J. Kanze wrote:
|> >
|> > Jason Merrill <jason@cygnus.com> writes:
|> >
|> > |> >>>>> James Kuyper <kuyper@wizard.net> writes:
|> > |>
|> > |> > No, the standard requires that the variadic functions be treated as a
|> > |> > less acceptable match.
|> > |>
|> > |> Please provide a quote to back this up. I thought so too, but was unable
|> > |> to find anything in the standard to this effect.
|> >
|> > I missed this one earlier, but 13.3.3.2/2 seems quite explicit:
|> >
|> > When comparing the basic forms of implicit conversion sequences (as
|> > defined in _over.best.ics_)
|> >
|> > -- a standard conversion sequence (_over.ics.scs_) is a better
|> > conversion sequence than a user-defined conversion sequence or an
|> > ellipsis conversion sequence, and
|> >
|> > -- a user-defined conversion sequence (_over.ics.user_) is a better
|> > conversion sequence than an ellipsis conversion sequence
|> > (_over.ics.ellipsis_).
|> >
|>
|> | 13.3.3.1.3 Ellipsis conversion sequences
|> [over.ics.ellipsis]
|> |
|> |1 An ellipsis conversion sequence occurs when an argument in a
|> function
|> | call is matched with the ellipsis parameter specification of the
|> func-
|> | tion called.
|>
|> The case being discussed involved fn(int) and fn(int, ...), as possible
|> matches to fn(1). Since there is no argument matching the ellipsis,
|> there is no ellipsis conversion. Therefore, there is nothing to mark the
|> variadic function as an inferior match. At least, that's the simplest
|> way to explain why the compiler complained that the function call was
|> ambiguous. I think that a variadic funtion should always be an inferior
|> match, but I don't think the quoted wording says so.
Sorry. The article I was responding to didn't mention the exact case.
As far as I can tell, defining "f( int )" and "f( int , ... )", then
calling the function with a single int, is, and always has been,
ambiguous.
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient e objet --
-- Beratung in objektorientierter Datenverarbeitung
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1998/06/11 Raw View
Jason Merrill <jason@cygnus.com> writes:
|> >>>>> James Kuyper <kuyper@wizard.net> writes:
|>
|> > No, the standard requires that the variadic functions be treated as a
|> > less acceptable match.
|>
|> Please provide a quote to back this up. I thought so too, but was unable
|> to find anything in the standard to this effect.
I missed this one earlier, but 13.3.3.2/2 seems quite explicit:
When comparing the basic forms of implicit conversion sequences (as
defined in _over.best.ics_)
-- a standard conversion sequence (_over.ics.scs_) is a better
conversion sequence than a user-defined conversion sequence or an
ellipsis conversion sequence, and
-- a user-defined conversion sequence (_over.ics.user_) is a better
conversion sequence than an ellipsis conversion sequence
(_over.ics.ellipsis_).
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient e objet --
-- Beratung in objektorientierter Datenverarbeitung
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/06/12 Raw View
J. Kanze wrote:
>
> Jason Merrill <jason@cygnus.com> writes:
>
> |> >>>>> James Kuyper <kuyper@wizard.net> writes:
> |>
> |> > No, the standard requires that the variadic functions be treated as a
> |> > less acceptable match.
> |>
> |> Please provide a quote to back this up. I thought so too, but was unable
> |> to find anything in the standard to this effect.
>
> I missed this one earlier, but 13.3.3.2/2 seems quite explicit:
>
> When comparing the basic forms of implicit conversion sequences (as
> defined in _over.best.ics_)
>
> -- a standard conversion sequence (_over.ics.scs_) is a better
> conversion sequence than a user-defined conversion sequence or an
> ellipsis conversion sequence, and
>
> -- a user-defined conversion sequence (_over.ics.user_) is a better
> conversion sequence than an ellipsis conversion sequence
> (_over.ics.ellipsis_).
>
| 13.3.3.1.3 Ellipsis conversion sequences
[over.ics.ellipsis]
|
|1 An ellipsis conversion sequence occurs when an argument in a
function
| call is matched with the ellipsis parameter specification of the
func-
| tion called.
The case being discussed involved fn(int) and fn(int, ...), as possible
matches to fn(1). Since there is no argument matching the ellipsis,
there is no ellipsis conversion. Therefore, there is nothing to mark the
variadic function as an inferior match. At least, that's the simplest
way to explain why the compiler complained that the function call was
ambiguous. I think that a variadic funtion should always be an inferior
match, but I don't think the quoted wording says so.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Mark Williams <markw@silicon-spice.com>
Date: 1998/06/12 Raw View
J. Kanze wrote:
> Jason Merrill <jason@cygnus.com> writes:
>
> |> >>>>> James Kuyper <kuyper@wizard.net> writes:
> |>
> |> > No, the standard requires that the variadic functions be treated as a
> |> > less acceptable match.
> |>
> |> Please provide a quote to back this up. I thought so too, but was unable
> |> to find anything in the standard to this effect.
>
> I missed this one earlier, but 13.3.3.2/2 seems quite explicit:
>
> When comparing the basic forms of implicit conversion sequences (as
> defined in _over.best.ics_)
>
> -- a standard conversion sequence (_over.ics.scs_) is a better
> conversion sequence than a user-defined conversion sequence or an
> ellipsis conversion sequence, and
>
> -- a user-defined conversion sequence (_over.ics.user_) is a better
> conversion sequence than an ellipsis conversion sequence
> (_over.ics.ellipsis_).
But this is not actually relevant in this case, because there is no argument
corresponding to the ellipsis, and hence no ellipsis conversion involved.
void f(int...);
void f(int);
void foo()
{
f(7); // ambiguous, because all (one :-) of the arguments are equally good
matches.
}
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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Jason Merrill <jason@cygnus.com>
Date: 1998/05/23 Raw View
>>>>> James Kuyper <kuyper@wizard.net> writes:
> No, the standard requires that the variadic functions be treated as a
> less acceptable match.
Please provide a quote to back this up. I thought so too, but was unable
to find anything in the standard to this effect.
Jason
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Nathan Sidwell <nathan@cs.bris.ac.uk>
Date: 1998/05/20 Raw View
With varadic functions there appears to be a contradiction in the
overload resolution I obtain from g++ (2.8.1) and Sun CC (4.1). I cannot
determine what the correct behaviour should be from my draft standard
(Dec 1996 draft).
Here's some example code,
void fn(int);
void fn(int, int);
void fn(int, ...);
int main()
{
fn(1);
fn(1, 1);
fn(1, 1.5);
}
both compilers think fn(int) and fn(int, ...) are equally good
candidates for the call fn(1). Is this intended by the standard?
If so, it appears odd that fn(int, int) is better than fn(int, ...) for
the call fn(1, 1). I.e. an exact match of an argument is better than an
elipsis match (13.3.3.2 para2, but an ellipsis match is better than no
argument.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/05/21 Raw View
Nathan Sidwell wrote:
>
> With varadic functions there appears to be a contradiction in the
> overload resolution I obtain from g++ (2.8.1) and Sun CC (4.1). I cannot
> determine what the correct behaviour should be from my draft standard
> (Dec 1996 draft).
>
> Here's some example code,
> void fn(int);
> void fn(int, int);
> void fn(int, ...);
>
> int main()
> {
> fn(1);
> fn(1, 1);
> fn(1, 1.5);
> }
> both compilers think fn(int) and fn(int, ...) are equally good
> candidates for the call fn(1). Is this intended by the standard?
No, the standard requires that the variadic functions be treated as a
less acceptable match.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]