C++ Logo


Advanced search

Re: Implicit conversion sequence from literal 0

From: Phil <std-discussion_at_[hidden]>
Date: Mon, 9 Jan 2023 01:13:01 +0100
> 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?

As far as I know, there can’t be no non-existing conversion sequence, but a sequence can happen to be empty, i.e. without any conversions.

That being said, there is specified an „implicit null pointer conversion“ from a „null pointer constant“, which is either an „integer literal with value 0“ or a „prvalue of type std::nullptr_t“.

If the evaluated argument is not a „null pointer constant“, there is no „implicit null pointer conversion“ and therefore it could happen that the conversion sequence for that argument is empty and therefore unable to convert.

According to [over.match.viable]/4, a function F is only considered viable, if (despite other requirements) there exists for each argument an implicit conversion sequence **that converts that argument to the corresponding parameter of F**.

So, given `foo(1, 1)`, there is no implicit conversion sequence that converts literal 1 to void* -> that overload is a candidate but not even viable at all.

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

At least by [over.match.viable] and [over.match.best] (and generally by many others regarding different topics).

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

The call is ill-formed.

Kind Regards

Received on 2023-01-09 00:13:16