From 10e106ae47c5a9450623d9874fdfd0c0aee54f26 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 27 Mar 2023 22:09:02 +0200 Subject: [PATCH] QResultStore::moveResult(): refuse to move from lvalues The T&& result argument is deduced, therefore result is a Universal Reference and as such can bind to lvalues, not just rvalues. If passed an lvalue, the function would happily move away from it, which is not what the doctor prescribed. Catch the attempt with a static assertion. Pick-to: 6.5 Change-Id: Iff8c1abd5dcb1043ed94ba76570be5ba3d6f92da Reviewed-by: Fabian Kosmale --- src/corelib/thread/qresultstore.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h index de5c31e91f..083290f9b7 100644 --- a/src/corelib/thread/qresultstore.h +++ b/src/corelib/thread/qresultstore.h @@ -149,6 +149,8 @@ public: template int moveResult(int index, T &&result) { + static_assert(!std::is_reference_v, "trying to move from an lvalue!"); + if (containsValidResultItem(index)) // reject if already present return -1;