Skip to content

Commit 7e395b9

Browse files
pypingouclaude
authored andcommitted
Fix pessimizing-move warnings in future/promise tests
GCC 14's -Werror=pessimizing-move detects std::move() on return values, which prevents copy elision and forces unnecessary move operations. Solution: remove std::move() from temporary return values and let the compiler apply copy elision optimization. Applied to 7 instances across: - base_interruptible_future_test.cpp (4 instances) - interruptible_shared_future_test.cpp (2 instances) - task_result_test.cpp (1 instance) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Leonardo Rossetti <lrossett@redhat.com>
1 parent e0e4617 commit 7e395b9

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

score/concurrency/future/base_interruptible_future_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ TYPED_TEST(BaseInterruptibleFutureTest, WaitReturnsOnlyAfterValueWasSet)
316316

317317
BaseInterruptibleFutureTest<TypeParam>::SetPromise(this->promise_);
318318

319-
auto expected = std::move(async_future.get());
319+
auto expected = async_future.get();
320320
EXPECT_TRUE(expected.has_value());
321321
}
322322

@@ -351,7 +351,7 @@ TYPED_TEST(BaseInterruptibleFutureTest, WaitForReturnsTimeoutErrorWhenValueWasNo
351351
return this->future_->WaitFor(stop_token, TIMEOUT);
352352
});
353353

354-
auto expected = std::move(async_future.get());
354+
auto expected = async_future.get();
355355
ASSERT_FALSE(expected.has_value());
356356
EXPECT_EQ(expected.error(), Error::kTimeout);
357357
}
@@ -388,7 +388,7 @@ TYPED_TEST(BaseInterruptibleFutureTest, WaitForReturnsWhenValueIsSet)
388388
});
389389
BaseInterruptibleFutureTest<TypeParam>::SetPromise(this->promise_);
390390

391-
auto expected = std::move(async_future.get());
391+
auto expected = async_future.get();
392392
EXPECT_TRUE(expected.has_value());
393393
}
394394

@@ -400,7 +400,7 @@ TYPED_TEST(BaseInterruptibleFutureTest, WaitUntilReturnsTimeoutErrorWhenValueWas
400400
return this->future_->WaitUntil(stop_token, std::chrono::steady_clock::now() + TIMEOUT);
401401
});
402402

403-
auto expected = std::move(async_future.get());
403+
auto expected = async_future.get();
404404
ASSERT_FALSE(expected.has_value());
405405
EXPECT_EQ(expected.error(), Error::kTimeout);
406406
}

score/concurrency/future/interruptible_shared_future_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ TYPED_TEST(InterruptibleSharedFutureTest, GetReturnsOnlyAfterValueWasSet)
349349

350350
InterruptibleSharedFutureTest<TypeParam>::SetPromise(this->promise_);
351351

352-
auto expected = std::move(async_future.get());
352+
auto expected = async_future.get();
353353
InterruptibleSharedFutureTest<TypeParam>::ExpectCorrectValue(expected);
354354
}
355355

@@ -358,7 +358,7 @@ TYPED_TEST(InterruptibleSharedFutureTest, GetReturnsErrorWhenSet)
358358
this->promise_.SetError(Error::kFutureAlreadyRetrieved);
359359

360360
score::cpp::stop_token stop_token{};
361-
auto expected = std::move(this->future_.Get(stop_token));
361+
auto expected = this->future_.Get(stop_token);
362362
ASSERT_FALSE(expected.has_value());
363363
EXPECT_EQ(expected.error(), Error::kFutureAlreadyRetrieved);
364364
}

score/concurrency/task_result_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class TaskResultContinuationTest : public ::testing::Test
157157
public:
158158
typename T::TaskType Make()
159159
{
160-
return std::move(T::Make(promise_));
160+
return T::Make(promise_);
161161
}
162162

163163
void ExpectCallNTimes(std::uint16_t n)

0 commit comments

Comments
 (0)