Don't cast function call result to void as it can hide nodiscard warnings
Summary:
When assigning a function whose return type is marked `nodiscard` to a `Function<void(Args...)>`, the fact that we are internally explicitly casting the result of the function call to `void` hides the `nodiscard` warning.
For instance:
```
struct [[nodiscard]] DoNotIgnore {};
Function<void()> fn = [] { return DoNotIgnore{}; };
```
emits no warnings, and when `fn()` is invoked, the `DoNotIgnore` struct gets silently ignored.
This diff causes the warning to be emitted.
It is only enabled on compilers that support `if constexpr`. It could be supported on more compilers at the cost of one or more of the following:
* extra template instantiations
* an additional function dispatch
* SFINAE
* Spamming out 4 more specializations of the `FunctionTraits` template.
Reviewed By: yfeldblum
Differential Revision: D18668177
fbshipit-source-id: 0a2cd1366855a0582ab27bb157998d3a4bf4e5a0
Showing
Please register or sign in to comment