C++ Logo

std-discussion

Advanced search

Re: Implicit conversion sequence from literal 0

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Sun, 8 Jan 2023 23:34:08 +0000
On Sun, 8 Jan 2023 at 23:22, Phil <std-discussion_at_[hidden]> wrote:

> > What would you say happens for `foo(1, 1)`
>
> The concerns remains the same; int -> void* and int -> int for overload
> (1); int -> short and int -> short for overload (2).
>
> But this time, there is no known implicit conversion available from int->
> void*, because literal 1 is no null pointer constant and therefore it can
> not be converted to a pointer type implicitly. So, if there is no other
> implicit conversion for the first argument available, this overload is not
> considered viable at all but overload (2) still is - and it‘s therefore
> also the best.
>

I'm not following. Are you saying that an implicit conversion sequence from
int to void* does not exist? Or that it does exist but is not viable in
this case?

> where does that diverge from the process for `foo(0, 1)`?
>
> It diverge by [conv.ptr/1].
>

And at what point in the process is [conv.ptr]/1 considered?

> Let's forget about the second argument for now.
>
> That‘s not possible, since it all depends on the second argument. If we
> forget about the second argument we would end up with ambiguity


I'm fine with that. What follows from that ambiguity?

because both overloads will have a rank of „conversion“ (only if the
> argument is literal 0 - else, as explained above, the first overload is not
> considered viable at all)
>
> For overload (1) from int -> void* => conversion
> For overload (2) from int -> short => conversion

Received on 2023-01-08 23:34:22