From 2ff28236f6cb50f910eb8e5cdc70387bbc1c76b6 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 15 Apr 2025 16:46:00 +0200 Subject: [PATCH] Upgrade: address warnings -- pessimizing-move Oh this is an interesting one... GCC now highlights situations with `-Wpessimizing-move`, where an overly zealous developer attempts to optimise by `std::move`, which however prevents the compiler from applying the ''Return Value Optimisation'' The latter is mandatory since C++17, and essentially means that a value object created within a function and then returned (by value) will actually be created directly in the target location, possibly eliding a whole chain of delegating value returns. Thus: if we write `std::move(value)`, we change the returned type into an RValue reference, and thereby ''force the compiler'' to invoke a move-ctor.... --- src/lib/iter-source.hpp | 6 ++---- src/stage/interact/ui-coord.hpp | 1 + src/stage/interact/ui-location-solver.hpp | 2 +- src/stage/interact/view-spec-dsl.hpp | 2 +- src/stage/model/element-access.hpp | 2 +- tests/library/test/test-option-test.cpp | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lib/iter-source.hpp b/src/lib/iter-source.hpp index e0ea0e9fb..69bb18e88 100644 --- a/src/lib/iter-source.hpp +++ b/src/lib/iter-source.hpp @@ -150,8 +150,7 @@ namespace lib { static iterator build (IterSource& sourceImpl) { - return std::move( - startIteration (DataHandle{&sourceImpl, &detach_without_destroy})); + return startIteration (DataHandle{&sourceImpl, &detach_without_destroy}); } /** build an iterator frontend, thereby managing @@ -163,8 +162,7 @@ namespace lib { static iterator build (IterSource* sourceImplObject) { - return std::move( - startIteration (DataHandle{sourceImplObject, &destroy_managed_source})); + return startIteration (DataHandle{sourceImplObject, &destroy_managed_source}); } static iterator EMPTY_SOURCE; diff --git a/src/stage/interact/ui-coord.hpp b/src/stage/interact/ui-coord.hpp index 4aa675984..d8897a3a1 100644 --- a/src/stage/interact/ui-coord.hpp +++ b/src/stage/interact/ui-coord.hpp @@ -491,6 +491,7 @@ namespace interact { class LocationClause; + /** @remark the result of this builder is retrieved by creating an `UICoord(builder)` */ class UICoord::Builder : util::MoveOnly { diff --git a/src/stage/interact/ui-location-solver.hpp b/src/stage/interact/ui-location-solver.hpp index a004d5e88..bef4a0c06 100644 --- a/src/stage/interact/ui-location-solver.hpp +++ b/src/stage/interact/ui-location-solver.hpp @@ -277,7 +277,7 @@ namespace interact { // append ID of the new element to be created // unless it's already there (and thus exists) resolver.append (elementTypeID); - return move (resolver); + return move (resolver); //////////////////////////////////////////////////////////////////TICKET #1402 : need a better solution for the builder-terminal-op. (it collides with the templated UICoord ctor) // use the first suitable solution and exit } else diff --git a/src/stage/interact/view-spec-dsl.hpp b/src/stage/interact/view-spec-dsl.hpp index cff61f329..68d99f714 100644 --- a/src/stage/interact/view-spec-dsl.hpp +++ b/src/stage/interact/view-spec-dsl.hpp @@ -151,7 +151,7 @@ namespace interact { : LocatorSpec{ LocationRule{ LocationClause{ - UICoord{std::move (simpleLocationSpec)}}}} + UICoord{std::move (simpleLocationSpec)}}}} //////////////////////////////////////////////TICKET #1402 : how to go from Builder to UICoord? DSL design vs. constructor ambiguity { } operator string() const diff --git a/src/stage/model/element-access.hpp b/src/stage/model/element-access.hpp index d56c28770..a8035c880 100644 --- a/src/stage/model/element-access.hpp +++ b/src/stage/model/element-access.hpp @@ -182,7 +182,7 @@ namespace model { { UICoord::Builder targetLocation{destination.rebuild()}; performAccessTo (targetLocation, limitCreation); - return targetLocation; + return targetLocation; ////////////////////////////////////////////////////////////////////////////////TICKET #1402 : ambiguities related to the terminal Builder-operation and the UICoord constructors } diff --git a/tests/library/test/test-option-test.cpp b/tests/library/test/test-option-test.cpp index 026fd808e..0746147f9 100644 --- a/tests/library/test/test-option-test.cpp +++ b/tests/library/test/test-option-test.cpp @@ -65,7 +65,7 @@ namespace test { cout << "--> Testgroup=" << optparser->getTestgroup() << endl; cout << "--> Test-ID =" << (isnil(testID)? "--missing--" : testID ) << endl; cout << "--> remaining=" << args << endl; - return std::move (optparser); + return optparser; } void noOptions() { doIt (""); }