From 1079d210d19cc05275228a17c318e5bdbcdeff6c Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Sun, 18 Aug 2024 01:59:29 +0300 Subject: [PATCH] Fix an evaluated use of std::declval in qjnitypes.h While other compilers don't seem to have trouble with this, the latest NDK (27) compiler does. That compiler diagnoses the empty-pack case, even though in that case there is no actual use of declval, as the pack-expanded expression contains no use of declval. For other compilers, that may work for functions that have no arguments, but will not work for any function that does have arguments; in that case, the attempt to use declval will always be ill-formed, and there will be an attempt to use declval. The fix is straightforward; we have a Ret(*)(Args...), its return type is simply Ret. So use a simple trait instead of the result of a call. Task-number: QTBUG-127468 Change-Id: I0dc9e1201914ab94acc2940870be7c6d8cb16c12 Pick-to: 6.7 Reviewed-by: Thiago Macieira (cherry picked from commit 236c6ec6f4c777d0534539f1c293cfc74006a6eb) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qjnitypes.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/corelib/kernel/qjnitypes.h b/src/corelib/kernel/qjnitypes.h index 4556dfa0a9a..d717c0c0d25 100644 --- a/src/corelib/kernel/qjnitypes.h +++ b/src/corelib/kernel/qjnitypes.h @@ -220,12 +220,14 @@ static constexpr auto makeTupleFromArgs(Ret (*)(JNIEnv *, jclass, Args...), va_l return makeTupleFromArgsHelper(args); } -// Get the return type of a function point -template -auto nativeFunctionReturnType(Ret(*function)(Args...)) +template +struct NativeFunctionReturnType {}; + +template +struct NativeFunctionReturnType { - return function(std::declval()...); -} + using type = Ret; +}; } // namespace Detail } // namespace QtJniMethods @@ -236,7 +238,7 @@ auto nativeFunctionReturnType(Ret(*function)(Args...)) // the actual function with. This then takes care of implicit conversions, // e.g. a jobject becomes a QJniObject. #define Q_DECLARE_JNI_NATIVE_METHOD_HELPER(Method) \ -static decltype(QtJniMethods::Detail::nativeFunctionReturnType(Method)) \ +static QtJniMethods::Detail::NativeFunctionReturnType::type \ va_##Method(JNIEnv *env, jclass thiz, ...) \ { \ va_list args; \