From 9ebc45c754ed842e75f928aae5aab39790bd2ef3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Aug 2024 11:16:27 +0200 Subject: [PATCH] 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 Reviewed-by: Volker Hilsheimer (cherry picked from commit 832e47ca44d3af1b7a3f722bad2a1d0c6fd56b5f) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qobjectdefs_impl.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index 1e953f29b6c..8bb2c7c3f01 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -58,18 +58,17 @@ namespace QtPrivate { struct FunctorCallBase { template - 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) { - using SlotRet = decltype(fn()); - if constexpr (std::is_void_v || std::is_void_v) { - Q_UNUSED(args); + if constexpr (std::is_void_v || std::is_void_v>) { + std::forward(fn)(); } else { - if (args[0]) { - *reinterpret_cast(args[0]) = fn(); - return; - } + if (args[0]) + *reinterpret_cast(args[0]) = std::forward(fn)(); + else + [[maybe_unused]] auto r = std::forward(fn)(); } - fn(); } };