From 956f7a94566d3ddb63d79d49ad047ec1a6ab03cc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 Oct 2025 10:36:25 +0200 Subject: QUndoStack: fix two Coverity COPY_INSTEAD_OF_MOVE warnings Coverity complained that, since the ActionState struct contains a QString, a copy is expensive while a move is possible. Make it so. To avoid explicit std::move() far away from the end of the scope (which impairs readability), use C++17 if-with-initializer to reduce the scope of the newX ActionState objects. This is a drive-by, since to move from them, we need to de-const the variables, anyway. Amends 31b0dadb0f371fc94652782c28024f135a0b6f4b. Pick-to: 6.10 6.8 Coverity-Id: 896353 Coverity-Id: 896351 Task-number: QTBUG-138567 Change-Id: Id365d9bd91773452d16634a3b862f3d23ad650b9 Reviewed-by: Edward Welbourne Reviewed-by: Richard Moe Gustavsen Reviewed-by: Ali Kianian --- src/gui/util/qundostack.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/gui/util/qundostack.cpp') diff --git a/src/gui/util/qundostack.cpp b/src/gui/util/qundostack.cpp index 3d1d8a2b788..27b131cd733 100644 --- a/src/gui/util/qundostack.cpp +++ b/src/gui/util/qundostack.cpp @@ -425,16 +425,16 @@ void QUndoStackPrivate::setIndex(int idx, bool clean) emit q->indexChanged(index); } - const ActionState newUndoState{q->canUndo(), q->undoText()}; - if (indexChanged || newUndoState != undoActionState) { - undoActionState = newUndoState; + if (ActionState newUndoState{q->canUndo(), q->undoText()}; + indexChanged || newUndoState != undoActionState) { + undoActionState = std::move(newUndoState); emit q->canUndoChanged(undoActionState.enabled); emit q->undoTextChanged(undoActionState.text); } - const ActionState newRedoState{q->canRedo(), q->redoText()}; - if (indexChanged || newRedoState != redoActionState) { - redoActionState = newRedoState; + if (ActionState newRedoState{q->canRedo(), q->redoText()}; + indexChanged || newRedoState != redoActionState) { + redoActionState = std::move(newRedoState); emit q->canRedoChanged(redoActionState.enabled); emit q->redoTextChanged(redoActionState.text); } -- cgit v1.2.3