Skip to content

Commit 935101e

Browse files
committed
fix: issues found by SonarCloud
1 parent ee956b2 commit 935101e

File tree

6 files changed

+8
-90
lines changed

6 files changed

+8
-90
lines changed

examples/sync_generator_adapter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ wwa::coro::async_generator<int> async_iota(int start = 0)
2020
int main()
2121
{
2222
//! [usage]
23-
wwa::coro::sync_generator_adapter<int> sync_iota(async_iota(10));
23+
wwa::coro::sync_generator_adapter sync_iota(async_iota(10));
2424

25-
for (auto& n : sync_iota | std::views::take(5)) {
25+
for (const auto& n : sync_iota | std::views::take(5)) {
2626
std::cout << n << "\n";
2727
}
2828
//! [usage]

src/async_generator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class [[nodiscard]] async_generator {
130130
*
131131
* This method is called when the coroutine returns. Does nothing.
132132
*/
133-
constexpr void return_void() noexcept {}
133+
constexpr void return_void() const noexcept {}
134134

135135
/**
136136
* @brief Yields a value from the generator.
@@ -234,7 +234,7 @@ class [[nodiscard]] async_generator {
234234
* @brief Constructs a new yield operation.
235235
* @param consumer The consumer coroutine.
236236
*/
237-
constexpr yield_op(std::coroutine_handle<> consumer) noexcept : m_consumer(consumer) {}
237+
constexpr explicit yield_op(std::coroutine_handle<> consumer) noexcept : m_consumer(consumer) {}
238238

239239
/**
240240
* @brief Determines whether the coroutine should suspend or continue immediately.

src/detail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/// @cond INTERNAL
1818

1919
// NOLINTNEXTLINE(modernize-concat-nested-namespaces)
20-
namespace wwa::coro {
20+
namespace wwa::coro { // NOSONAR
2121

2222
/**
2323
* @brief Internal utility functions for coroutine handling.

src/eager_task.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class eager_task {
6161
* @internal
6262
* @test @a SimpleTaskDeathTest.UnhandledException ensures that the program terminates on an unhandled exception.
6363
*/
64-
[[noreturn]] void unhandled_exception() noexcept { std::terminate(); }
64+
[[noreturn]] void unhandled_exception() const noexcept { std::terminate(); }
6565

6666
/**
6767
* @brief Handles the exit out of the coroutine body.
@@ -85,7 +85,7 @@ class eager_task {
8585
* @internal
8686
* @test @a SimpleTaskTest.Basic
8787
*/
88-
constexpr auto initial_suspend() noexcept { return std::suspend_never{}; }
88+
[[nodiscard]] constexpr auto initial_suspend() const noexcept { return std::suspend_never{}; }
8989

9090
/**
9191
* @brief Issues an awaiter for final suspend point.
@@ -99,7 +99,7 @@ class eager_task {
9999
* @internal
100100
* @test @a SimpleTaskTest.Basic
101101
*/
102-
constexpr auto final_suspend() noexcept { return std::suspend_never{}; }
102+
[[nodiscard]] constexpr auto final_suspend() const noexcept { return std::suspend_never{}; }
103103

104104
/// @endcond
105105
};

src/generator.h

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -246,37 +246,6 @@ class [[nodiscard]] generator : public std::ranges::view_interface<generator<Res
246246
explicit iterator(std::coroutine_handle<promise_type> coroutine) noexcept : m_coroutine(coroutine) {}
247247
/// @endcond
248248

249-
/**
250-
* @brief Move constructor.
251-
*
252-
* Constructs a new iterator object by moving the coroutine handle from another iterator.
253-
*
254-
* @param other Another iterator.
255-
*/
256-
iterator(iterator&& other) noexcept : m_coroutine(std::exchange(other.m_coroutine, nullptr)) {}
257-
258-
/**
259-
* @brief Destructor.
260-
*/
261-
~iterator() = default;
262-
263-
/**
264-
* @brief Move assignment operator.
265-
*
266-
* Assigns the coroutine handle from another iterator to this iterator.
267-
*
268-
* @param other Another iterator.
269-
* @return Reference to this iterator.
270-
*/
271-
constexpr iterator& operator=(iterator&& other) noexcept
272-
{
273-
if (this != std::addressof(other)) {
274-
this->m_coroutine = std::exchange(other.m_coroutine, nullptr);
275-
}
276-
277-
return *this;
278-
}
279-
280249
/**
281250
* @brief Default constructor.
282251
*
@@ -286,26 +255,6 @@ class [[nodiscard]] generator : public std::ranges::view_interface<generator<Res
286255
*/
287256
iterator() noexcept = default;
288257

289-
/**
290-
* @brief Default copy constructor.
291-
*
292-
* @param other Another iterator.
293-
*
294-
* @internal
295-
* @test @a GeneratorTest.View
296-
* @note This constructor is required to satisfy the `std::ranges::view` concept.
297-
*/
298-
iterator(const iterator& other) = default;
299-
300-
/**
301-
* @brief Default assignment operator.
302-
*
303-
* @param other Another iterator (right hand side of the assignment operator).
304-
* @return A reference to self.
305-
* @note This operator is required to satisfy the `std::ranges::view` concept.
306-
*/
307-
iterator& operator=(const iterator& other) = default;
308-
309258
/**
310259
* @brief Compares two iterators.
311260
*

test/generator.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -366,37 +366,6 @@ TEST(GeneratorTest, EmptyGenerator)
366366
EXPECT_THROW(++it, bad_result_access);
367367
}
368368

369-
TEST(GeneratorIteratorTest, Move)
370-
{
371-
constexpr int v1 = 1;
372-
constexpr int v2 = 4;
373-
374-
auto g1 = value<decltype(v1)>(v1);
375-
auto g2 = value<decltype(v2)>(v2);
376-
377-
auto it1 = g1.begin();
378-
auto it2 = g2.begin();
379-
380-
it2 = std::move(it1);
381-
382-
EXPECT_EQ(*it2, v1);
383-
}
384-
385-
TEST(GeneratorIteratorTest, MoveSelf)
386-
{
387-
constexpr int expected = 1983;
388-
389-
auto g = value<decltype(expected)>(expected);
390-
391-
auto it = g.begin();
392-
#pragma clang diagnostic push
393-
#pragma clang diagnostic ignored "-Wself-move"
394-
it = std::move(it);
395-
#pragma clang diagnostic pop
396-
397-
EXPECT_EQ(*it, expected);
398-
}
399-
400369
TEST(GeneratorIteratorTest, AccessEndIterator)
401370
{
402371
auto g = value(1);

0 commit comments

Comments
 (0)