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:
Marc Mutz 2024-08-26 11:16:27 +02:00 committed by Qt Cherry-pick Bot
parent ac05ee3746
commit 9ebc45c754

View File

@ -58,19 +58,18 @@ namespace QtPrivate {
struct FunctorCallBase
{
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<SlotRet>) {
Q_UNUSED(args);
if constexpr (std::is_void_v<R> || std::is_void_v<std::invoke_result_t<Lambda>>) {
std::forward<Lambda>(fn)();
} else {
if (args[0]) {
*reinterpret_cast<R *>(args[0]) = fn();
return;
if (args[0])
*reinterpret_cast<R *>(args[0]) = std::forward<Lambda>(fn)();
else
[[maybe_unused]] auto r = std::forward<Lambda>(fn)();
}
}
fn();
}
};
/*