From b2bcf3b68a551b381bf6d10700e55518ea9d91e1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 27 Mar 2023 21:52:39 +0200 Subject: [PATCH] QResultStore: use unconditional move() in moveResult() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the move can fail, so can most likely the copy. Use of move_if_noexcept() therefore trades a faster potentially-throwing operation for a slower potentially-throwing operation. It is true that a throwing move ctor may leave the source object in a partially-formed state while the copy ctor may not (exceptions prove the rule, hello auto_ptr), but we shouldn't pessimize lazy coders (missing noexcept) to cater for borderline-buggy code (throwing move ctor that doesn't provide the strong exception guarantee). Yes, you can construct such situations (and something as simple as std::array is already affected), but we don't cater for these anywhere else in Qt, so why do it here? Change-Id: I728af8e87ed86f24326530f704a48df1f728ac98 Reviewed-by: Fabian Kosmale Reviewed-by: MÃ¥rten Nordheim --- src/corelib/thread/qresultstore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h index af559b7a96..de5c31e91f 100644 --- a/src/corelib/thread/qresultstore.h +++ b/src/corelib/thread/qresultstore.h @@ -152,7 +152,7 @@ public: if (containsValidResultItem(index)) // reject if already present return -1; - return addResult(index, static_cast(new T(std::move_if_noexcept(result)))); + return addResult(index, static_cast(new T(std::move(result)))); } template