Give some TLC to FunctorCallBase::call_internal()
The function takes `fn` by universal reference, so it should be `std::forward`ing `fn` before calling it. This includes the unevaluated contexts, so use `std::is_nothrow_invocable_v` and `std::invoke_result_t` instead of `noexcept(fn())` and `decltype(fn())`. The std traits take the value category into account automatically. Linters like to warn about universal/forwarding references without std::forward(), so this should be fixed even without and actual overloaded op() &/op() && present. The function passed as `fn` may also be marked as `[[nodiscard]]`, so make sure that we never ignore the return value (unless it's void) to avoid throwing warnings. As a drive-by, replace Q_UNUSED with [[maybe_unused]] and inline the SlotRet type alias into its only user. Amends f894f04c9d03878116de61c11d4591da67c10378. Change-Id: I5e045fc735f461a82244d7e80f81c2a9b1e69046 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 832e47ca44d3af1b7a3f722bad2a1d0c6fd56b5f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ac05ee3746
commit
9ebc45c754
@ -58,18 +58,17 @@ namespace QtPrivate {
|
|||||||
struct FunctorCallBase
|
struct FunctorCallBase
|
||||||
{
|
{
|
||||||
template <typename R, typename Lambda>
|
template <typename R, typename Lambda>
|
||||||
static void call_internal(void **args, Lambda &&fn) noexcept(noexcept(fn()))
|
static void call_internal([[maybe_unused]] void **args, Lambda &&fn)
|
||||||
|
noexcept(std::is_nothrow_invocable_v<Lambda>)
|
||||||
{
|
{
|
||||||
using SlotRet = decltype(fn());
|
if constexpr (std::is_void_v<R> || std::is_void_v<std::invoke_result_t<Lambda>>) {
|
||||||
if constexpr (std::is_void_v<R> || std::is_void_v<SlotRet>) {
|
std::forward<Lambda>(fn)();
|
||||||
Q_UNUSED(args);
|
|
||||||
} else {
|
} else {
|
||||||
if (args[0]) {
|
if (args[0])
|
||||||
*reinterpret_cast<R *>(args[0]) = fn();
|
*reinterpret_cast<R *>(args[0]) = std::forward<Lambda>(fn)();
|
||||||
return;
|
else
|
||||||
}
|
[[maybe_unused]] auto r = std::forward<Lambda>(fn)();
|
||||||
}
|
}
|
||||||
fn();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user