Should int(*)() be convertible to inplace_function<void()>?#159
Should int(*)() be convertible to inplace_function<void()>?#159Quuxplusone wants to merge 2 commits intoWG21-SG14:masterfrom
int(*)() be convertible to inplace_function<void()>?#159Conversation
|
@Quuxplusone I would personally prefer a fail. I am not a fan of silent issues, and this is clearly a programmer error. However, it may be necessary to conform to One could use |
You can use Ah! But we could just put the conversion under a compile-time flag like [EDIT already: I was missing that it would be difficult to test both behaviors. But that's a minor concern, and I guess the proper place to address it would be in the build matrix, not in the test code.] |
Before this patch, we reported that `is_convertible<int(*)(), inplace_function<void()>>`, but if you actually tried to do it, you got a compiler error down in the guts of `inplace_function`. After this patch, we let you do it. However, see issue WG21-SG14#150: I think anyone who relies on this behavior is probably doing so unintentionally (and their code is probably wrong). Therefore, maybe we should change our SFINAE so that `is_convertible<int(*)(), inplace_function<void()>>` would be `false`.
Put the "standard" behavior under a macro flag, and default to the "safer" behavior. That is, disallow the conversion by default.
|
Hmm, definitely prefer compile-time flag over warning. Afaik that wouldn't be standardizable in this fashion though.
In light of other design changes wanted for inplace_function, I'd recommend to close this hole early and avoid users becoming reliant on it. Imo the advantages of sticking with the existing std::function design and with that its known problems, like this and #158, do not outweigh the disadvantages.
My vote is for never allowing this conversion.
… On 23. May 2019, at 19:45, Quuxplusone ***@***.***> wrote:
compile-time flag
|
Before this patch, we reported that
is_convertible<int(*)(), inplace_function<void()>>,but if you actually tried to do it, you got a compiler error down in the guts
of
inplace_function.After this patch, we let you do it.
However, see issue #150: I think anyone who relies on this behavior is probably
doing so unintentionally (and their code is probably wrong). Therefore, maybe we
should change our SFINAE so that
is_convertible<int(*)(), inplace_function<void()>>would be
false.I'm posting this PR to get opinions (e.g. @Voultapher @p-groarke), not necessarily because I think it's the right approach (frankly I don't). Vice versa, if we decide to make
is_convertible<int(*)(), inplace_function<void()>> == false, then we'll have to bikeshed the right way to do that. Should we eliminate the special cases in ourdetail::is_invocable_r_impl, and if so, should we rename it so that people don't confuse it with the standardis_invocable_r?