-Richard
void f(float f);
void f(int) = delete; //Cannot call `f` with integers.
f(10); //Compile error.
f(20.0f); //OK.
On 21.01.2017 17:22, Nicol Bolas wrote:
>
> We didn't add `= delete` syntax to make error messages more reasonable
> (well OK, we did, but not in the way you mean). Part of the motivation
> of the feature was for cases where you want to /prevent/ implicit
> conversion of some parameters from some values, so you delete the
> alternatives you don't want the user to invoke:
I'm aware of that.
> The feature is working as intended. If `= delete` changed how overload
> resolution worked, then it wouldn't be doing its job. You are
> mis-applying the tool to a use case for which it was not intended.
Let me rephrase the original code:
struct foo
{
foo() = default;
foo(int) {}
operator std::string(); // implicitly convertible to std::string,
because why not
};
struct bar
{
bar(std::string) {}
bar(foo) = delete; // I only want really strings, not foo's
// delete's intended use case
};
foo operator+(foo, foo);
bar operator+(bar, int);
foo{} + 3; // error, ambiguous, thanks to delete
Yes, the example is silly, but you'll get the point.
> What you want would require a new feature.
I don't want a new feature. I don't event want to change how `= delete`
participates in overload resolution.
I just want to change how `deleted` constructor conversions are ranked
when doing overload resolution.
struct bar
{
bar(int);
__low_ranked bar(foo);
};
Because - as far as I can tell - deleted constructors are broken.
The overloads are ambiguous, as it can also convert `foo` to `bar` and
use the second overload, none is a better match.
This happens even though the constructor is deleted, it still
participates in overload resolution - by design.