Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should int(*)() be convertible to inplace_function<void()>? #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Quuxplusone
Copy link
Contributor

@Quuxplusone Quuxplusone commented May 1, 2019

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 our detail::is_invocable_r_impl, and if so, should we rename it so that people don't confuse it with the standard is_invocable_r?

@p-groarke
Copy link

@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 std::function. Would it be possible to add a custom warning for this?

One could use [[deprecated("reason")]](C++14) for it, though not very elegant and certainly not the correct warning type. Might be a stop gap while this is a library. I'm guessing here you can tag dispatch to a deprecated function.

@Quuxplusone
Copy link
Contributor Author

Quuxplusone commented May 23, 2019

Would it be possible to add a custom warning for this?

You can use [[deprecated("reason")]] as you propose — https://godbolt.org/z/cXpP8M — but as a usability matter, I wouldn't. Most codebases rightly have no notion of "warning"; either an issue is important enough that you make it an error (-Werror) and fix it, or it's a non-issue and so you suppress it. Nobody would run long-term with unfixed warnings in their build. So adding such a warning deliberately to inplace_function would just force users to choose between avoiding the conversion (i.e. the same outcome as if we'd made it a hard error in the first place), or adding -Wno-deprecated-declarations to their build flags (i.e. a worse outcome than the status quo).

Ah! But we could just put the conversion under a compile-time flag like #ifdef INPLACE_FUNCTION_INVOCABLE_AS_VOID! That would be pretty clean, I think, unless I'm missing something.

[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.
@Voultapher
Copy link
Contributor

Voultapher commented May 23, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants