Skip to content

Commit 710e30b

Browse files
committed
fix: issues found by SonarCloud
1 parent a0627eb commit 710e30b

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/task.h

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -176,30 +176,6 @@ struct promise_type<void> : promise_base<promise_type<void>> {
176176
void result_value() const { this->rethrow_if_exception(); }
177177
};
178178

179-
template<typename Promise>
180-
class awaiter_base {
181-
public:
182-
awaiter_base(std::coroutine_handle<Promise> coro) noexcept : m_coroutine(coro) {}
183-
184-
[[nodiscard]] constexpr bool await_ready() const noexcept { return detail::is_ready(this->m_coroutine); }
185-
186-
auto await_suspend(std::coroutine_handle<> awaiting) noexcept
187-
{
188-
this->m_coroutine.promise().set_next(awaiting);
189-
return this->m_coroutine;
190-
}
191-
192-
protected:
193-
auto coroutine()
194-
{
195-
detail::check_coroutine(this->m_coroutine);
196-
return this->m_coroutine;
197-
}
198-
199-
private:
200-
std::coroutine_handle<Promise> m_coroutine;
201-
};
202-
203179
} // namespace detail
204180

205181
/// @endcond
@@ -428,20 +404,32 @@ class [[nodiscard]] task {
428404
*/
429405
auto operator co_await() const& noexcept
430406
{
431-
struct awaiter : public detail::awaiter_base<promise_type> {
407+
struct awaiter {
408+
[[nodiscard]] constexpr bool await_ready() const noexcept { return detail::is_ready(this->coroutine); }
409+
410+
auto await_suspend(std::coroutine_handle<> awaiting) noexcept
411+
{
412+
this->coroutine.promise().set_next(awaiting);
413+
return this->coroutine;
414+
}
415+
432416
decltype(auto) await_resume()
433417
{
434-
auto& promise = this->coroutine().promise();
418+
detail::check_coroutine(this->coroutine);
419+
auto& promise = this->coroutine.promise();
435420
if constexpr (std::is_rvalue_reference_v<Result>) {
436421
return std::move(promise.result_value());
437422
}
438423
else {
439424
return promise.result_value();
440425
}
441426
}
427+
428+
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
429+
std::coroutine_handle<promise_type> coroutine;
442430
};
443431

444-
return awaiter(this->m_coroutine);
432+
return awaiter{this->m_coroutine};
445433
}
446434

447435
/**
@@ -457,15 +445,26 @@ class [[nodiscard]] task {
457445
auto operator co_await() && noexcept
458446
requires(!std::is_void_v<Result>)
459447
{
460-
struct awaiter : public detail::awaiter_base<promise_type> {
448+
struct awaiter {
449+
[[nodiscard]] constexpr bool await_ready() const noexcept { return detail::is_ready(this->coroutine); }
450+
451+
auto await_suspend(std::coroutine_handle<> awaiting) noexcept
452+
{
453+
this->coroutine.promise().set_next(awaiting);
454+
return this->coroutine;
455+
}
456+
461457
decltype(auto) await_resume()
462458
{
463-
auto coro = this->coroutine();
464-
return std::move(coro.promise().result_value());
459+
detail::check_coroutine(this->coroutine);
460+
return std::move(this->coroutine.promise().result_value());
465461
}
462+
463+
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
464+
std::coroutine_handle<promise_type> coroutine;
466465
};
467466

468-
return awaiter(this->m_coroutine);
467+
return awaiter{this->m_coroutine};
469468
}
470469

471470
private:

0 commit comments

Comments
 (0)