Skip to content

Commit bdb55e0

Browse files
committed
started to address clang-tidy reports
1 parent a760a29 commit bdb55e0

File tree

10 files changed

+50
-24
lines changed

10 files changed

+50
-24
lines changed

tests/beman/execution26/exec-connect.test.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ----------------------------------------------------------------------------
1515

1616
namespace {
17-
enum class kind { plain, domain };
17+
enum class kind: unsigned char { plain, domain };
1818
template <kind, test_std::receiver Receiver>
1919
struct state {
2020
using operation_state_concept = test_std::operation_state_t;
@@ -24,6 +24,7 @@ struct state {
2424
template <typename R>
2525
state(int value, R&& r) : value(value), receiver(std::forward<R>(r)) {}
2626
state(state&&) = delete;
27+
~state() = default;
2728
auto start() noexcept -> void {}
2829
};
2930

@@ -41,8 +42,9 @@ struct rvalue_sender {
4142
using sender_concept = test_std::sender_t;
4243
int value{};
4344

44-
rvalue_sender(int value) : value(value) {}
45+
explicit rvalue_sender(int value) : value(value) {}
4546
rvalue_sender(rvalue_sender&&) = default;
47+
auto operator= (rvalue_sender&&) -> rvalue_sender& = default;
4648

4749
template <typename Receiver>
4850
auto connect(Receiver&& receiver) && -> state<kind::plain, Receiver> {
@@ -59,8 +61,9 @@ struct receiver {
5961
int value{};
6062
bool* set_stopped_called{};
6163

62-
receiver(int value, bool* set_stopped_called = {}) : value(value), set_stopped_called(set_stopped_called) {}
64+
explicit receiver(int value, bool* set_stopped_called = {}) : value(value), set_stopped_called(set_stopped_called) {}
6365
receiver(receiver&&) = default;
66+
auto operator=(receiver&&) -> receiver& = default;
6467
auto operator==(const receiver&) const -> bool = default;
6568

6669
auto get_env() const noexcept -> env { return {this->value + 2}; }
@@ -91,8 +94,10 @@ struct domain_receiver {
9194
using receiver_concept = test_std::receiver_t;
9295
int value{};
9396

94-
domain_receiver(int value) : value(value) {}
97+
explicit domain_receiver(int value) : value(value) {}
9598
domain_receiver(domain_receiver&&) = default;
99+
auto operator= (domain_receiver&&) -> domain_receiver& = default;
100+
96101
auto operator==(const domain_receiver&) const -> bool = default;
97102

98103
auto get_env() const noexcept -> domain_env { return {}; }
@@ -217,12 +222,13 @@ auto test_connect_awaitable() -> void {
217222
this->iv = value;
218223
this->bv = true;
219224
}
220-
auto set_error(::std::exception_ptr error) && noexcept -> void {
225+
auto set_error(::std::exception_ptr const& error) && noexcept -> void {
221226
try {
222227
std::rethrow_exception(error);
223228
} catch (const std::runtime_error&) {
224229
this->bv = true;
225230
} catch (...) {
231+
this->bv = false;
226232
}
227233
}
228234
auto set_stopped() && noexcept -> void {}
@@ -285,7 +291,7 @@ auto test_connect_with_awaiter() -> void {
285291
using receiver_concept = test_std::receiver_t;
286292
bool& result;
287293
auto set_value(int i) && noexcept -> void { this->result = i == 17; }
288-
auto set_error(std::exception_ptr) && noexcept -> void {}
294+
auto set_error(std::exception_ptr const&) && noexcept -> void {}
289295
auto set_stopped() && noexcept -> void {}
290296
};
291297

tests/beman/execution26/exec-get-env.test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct with_non_env;
1313
struct non_env {
1414
private:
1515
friend struct with_non_env;
16+
non_env() = default;
17+
non_env(non_env&&) = delete;
1618
~non_env() = default;
1719
};
1820
struct with_non_env {

tests/beman/execution26/exec-sched.test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct no_scheduler_concept {
3131

3232
struct not_queryable {
3333
using scheduler_concept = test_std::scheduler_t;
34+
not_queryable() = default;
35+
not_queryable(not_queryable&&) = default;
3436
~not_queryable() = delete;
3537
auto schedule() -> sender<env<not_queryable>> { return {}; }
3638
auto operator==(const not_queryable&) const -> bool = default;
@@ -49,6 +51,8 @@ struct not_equality_comparable {
4951
struct not_copy_constructible {
5052
using scheduler_concept = test_std::scheduler_t;
5153
not_copy_constructible(const not_copy_constructible&) = delete;
54+
not_copy_constructible(not_copy_constructible&&) = default;
55+
~not_copy_constructible() = default;
5256
auto schedule() -> sender<env<not_copy_constructible>> { return {}; }
5357
auto operator==(const not_copy_constructible&) const -> bool = default;
5458
};

tests/beman/execution26/exec-schedule.test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ auto test_schedule(Scheduler&& sched) {
3434
if constexpr (Expect) {
3535
static_assert(noexcept(test_std::schedule(std::forward<Scheduler>(sched))) ==
3636
noexcept(std::forward<Scheduler>(sched).schedule()));
37+
auto value{sched.value};
3738
auto s = test_std::schedule(std::forward<Scheduler>(sched));
38-
ASSERT(s.value == sched.value);
39+
ASSERT(s.value == value);
3940
}
4041
}
4142
} // namespace

tests/beman/execution26/exec-then.test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ auto test_then_multi_type() -> void {
147147

148148
auto test_then_value() -> void {
149149
ASSERT(std::tuple{17} ==
150-
*test_std::sync_wait(test_std::just(5, 12) | test_std::then([](int a, int b) { return a + b; })));
150+
test_std::sync_wait(test_std::just(5, 12) | test_std::then([](int a, int b) { return a + b; })).value_or(0));
151151
ASSERT(std::tuple{17} ==
152152
test_std::sync_wait(test_std::just_error(17) | test_std::upon_error([](int a) { return a; })));
153153
ASSERT(std::tuple{17} ==
@@ -183,15 +183,16 @@ struct allocator_fun {
183183
std::pmr::polymorphic_allocator<> alloc;
184184
std::byte* data{nullptr};
185185

186-
allocator_fun(std::pmr::polymorphic_allocator<> alloc) : alloc(alloc), data(alloc.allocate(1)) {}
186+
explicit allocator_fun(std::pmr::polymorphic_allocator<> alloc) : alloc(alloc), data(alloc.allocate(1)) {}
187187
allocator_fun(const allocator_fun&, std::pmr::polymorphic_allocator<> = {}) {}
188-
allocator_fun(allocator_fun&& other) : alloc(other.alloc), data(std::exchange(other.data, nullptr)) {}
188+
allocator_fun(allocator_fun&& other) noexcept: alloc(other.alloc), data(std::exchange(other.data, nullptr)) {}
189189
allocator_fun(allocator_fun&& other, std::pmr::polymorphic_allocator<> alloc)
190190
: alloc(alloc), data(alloc == other.alloc ? std::exchange(other.data, nullptr) : alloc.allocate(1)) {}
191191
~allocator_fun() {
192192
if (this->data)
193193
this->alloc.deallocate(this->data, 1u);
194194
}
195+
auto operator= (allocator_fun&&) -> allocator_fun = delete;
195196
auto operator()(auto&&...) const {}
196197
};
197198

tests/beman/execution26/execution-queryable-concept.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ template <typename T>
1111
concept has_foo = test_std::detail::queryable<T> && requires(T t) { t.foo; };
1212

1313
class non_destructible {
14-
~non_destructible() = default;
14+
~non_destructible() = delete;
1515
};
1616

1717
template <typename T>

tests/beman/execution26/include/test/stop_token.hpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <test/execution.hpp>
1010

1111
#include <algorithm>
12+
#include <array>
1213
#include <atomic>
1314
#include <cassert>
1415
#include <chrono>
@@ -50,7 +51,7 @@ inline auto test::stop_visible(Token token, Stop stop) -> void {
5051
// was requested.
5152
// Reference: [thread.stoptoken.intro] p3
5253

53-
Token tokens[] = {token, token, token, token};
54+
std::array<Token, 4> tokens{token, token, token, token};
5455

5556
auto predicate = [](auto&& t) { return t.stop_requested(); };
5657
ASSERT((::std::ranges::none_of(tokens, predicate)));
@@ -82,7 +83,7 @@ inline auto test::stop_callback(Token token, Stop stop) -> void {
8283

8384
struct Callback {
8485
Data* data;
85-
Callback(Data* data) : data(data) {}
86+
explicit Callback(Data* data) : data(data) {}
8687
auto operator()() {
8788
++this->data->count;
8889
this->data->stop_requested = this->data->token.stop_requested();
@@ -91,7 +92,7 @@ inline auto test::stop_callback(Token token, Stop stop) -> void {
9192

9293
Data data{token};
9394

94-
::test_std::stop_callback_for_t<Token, Callback> cb0(token, &data);
95+
::test_std::stop_callback_for_t<Token, Callback> cb0(token, Callback{&data});
9596
ASSERT(data.count == 0);
9697
ASSERT(data.stop_requested == false);
9798
stop();
@@ -102,7 +103,7 @@ inline auto test::stop_callback(Token token, Stop stop) -> void {
102103
stop();
103104
ASSERT(data.count == 1);
104105

105-
::test_std::stop_callback_for_t<Token, Callback> cb1(token, &data);
106+
::test_std::stop_callback_for_t<Token, Callback> cb1(token, Callback{&data});
106107
ASSERT(data.count == 2);
107108
stop();
108109
ASSERT(data.count == 2);
@@ -122,13 +123,13 @@ auto test::stop_callback_dtor_deregisters(Token token, Stop stop) -> void {
122123

123124
struct Callback {
124125
bool* ptr;
125-
Callback(bool* ptr) : ptr(ptr) {}
126+
explicit Callback(bool* ptr) : ptr(ptr) {}
126127
auto operator()() { *this->ptr = true; }
127128
};
128129

129130
bool flag{};
130131
::std::invoke([token, &flag] {
131-
::test_std::stop_callback_for_t<Token, Callback> cb(token, &flag);
132+
::test_std::stop_callback_for_t<Token, Callback> cb(token, Callback{&flag});
132133
ASSERT(flag == false);
133134
});
134135

@@ -164,7 +165,7 @@ inline auto test::stop_callback_dtor_other_thread(Token token, Stop stop) -> voi
164165
};
165166
struct Callback {
166167
Data* data;
167-
Callback(Data* data) : data(data) {}
168+
explicit Callback(Data* data) : data(data) {}
168169
auto operator()() -> void {
169170
using namespace ::std::chrono_literals;
170171
{
@@ -181,7 +182,7 @@ inline auto test::stop_callback_dtor_other_thread(Token token, Stop stop) -> voi
181182
Data data;
182183

183184
using CB = ::test_std::stop_callback_for_t<Token, Callback>;
184-
::std::unique_ptr<CB> ptr(new CB(token, &data));
185+
::std::unique_ptr<CB> ptr(new CB(token, Callback{&data}));
185186

186187
::std::thread thread([&ptr, &data] {
187188
{
@@ -210,19 +211,23 @@ inline auto test::stop_callback_dtor_same_thread(Token token, Stop stop) -> void
210211
// - Then the deregistration does not block.
211212
// Reference: [stoptoken.concepts] p4
212213
struct Base {
214+
Base() = default;
215+
Base(Base&&) = delete;
213216
virtual ~Base() = default;
214217
};
215218
struct Callback {
216219
::std::unique_ptr<Base>* self;
217-
Callback(::std::unique_ptr<Base>* self) : self(self) {}
220+
explicit Callback(::std::unique_ptr<Base>* self) : self(self) {}
221+
Callback(Callback const&) = default;
222+
Callback(Callback&&) = default;
218223
auto operator()() { this->self->reset(); }
219224
};
220225
struct Object : Base {
221226
::test_std::stop_callback_for_t<Token, Callback> cb;
222-
Object(Token token, ::std::unique_ptr<Base>* self) : cb(token, self) {}
227+
Object(Token token, ::std::unique_ptr<Base>* self) : cb(std::move(token), Callback{self}) {}
223228
};
224229
::std::unique_ptr<Base> ptr;
225-
ptr.reset(new Object(token, &ptr));
230+
ptr.reset(new Object(std::move(token), &ptr));
226231

227232
::std::atomic<bool> done{};
228233
::std::thread thread([&done] {

tests/beman/execution26/stopcallback-general.test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <concepts>
77
#include <type_traits>
88

9+
namespace {
910
auto test_stop_callback_interface() -> void {
1011
// Reference: [stopcallback.general] p1
1112
struct ThrowInit {};
@@ -35,5 +36,6 @@ auto test_stop_callback_interface() -> void {
3536

3637
::test_std::stop_callback cb(ctoken, Callback(ThrowInit()));
3738
}
39+
}
3840

3941
TEST(stopcallback_general) { test_stop_callback_interface(); }

tests/beman/execution26/stopsource-mem.test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <beman/execution26/stop_token.hpp>
55
#include "test/execution.hpp"
66

7+
namespace {
78
auto test_stopsource_swap() -> void {
89
// Plan:
910
// - Given two engaged stop sources.
@@ -119,6 +120,7 @@ auto test_stopsource_request_stop() -> void {
119120
ASSERT(res4 == false);
120121
ASSERT(not disengaged.stop_requested());
121122
}
123+
}
122124

123125
TEST(stopsource_mem) {
124126
test_stopsource_swap();

tests/beman/execution26/stoptoken-mem.test.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
#include <beman/execution26/stop_token.hpp>
5+
#include <array>
56
#include <memory>
67
#include "test/execution.hpp"
78
#include "test/stop_token.hpp"
89

10+
namespace {
911
auto test_stop_token_swap() -> void {
1012
// Plan:
1113
// - Given two pairs of stop_tokens compare equal within the pair
@@ -15,8 +17,8 @@ auto test_stop_token_swap() -> void {
1517
// Reference: [stoptoken.mem] p1
1618

1719
::test_std::stop_source s0, s1;
18-
::test_std::stop_token pair0[] = {s0.get_token(), s0.get_token()};
19-
::test_std::stop_token pair1[] = {s1.get_token(), s1.get_token()};
20+
::std::array<::test_std::stop_token, 2> pair0 = {s0.get_token(), s0.get_token()};
21+
::std::array<::test_std::stop_token, 2> pair1 = {s1.get_token(), s1.get_token()};
2022

2123
ASSERT(pair0[0] == pair0[1]);
2224
ASSERT(pair1[0] == pair1[1]);
@@ -85,6 +87,7 @@ auto test_stop_token_stop_possible() -> void {
8587
ASSERT(unstopped_token.stop_possible() == false);
8688
ASSERT(stopped_token.stop_possible() == true);
8789
}
90+
}
8891

8992
TEST(stoptoken_mem) {
9093
static_assert(::test_std::stoppable_token<::test_std::stop_token>);

0 commit comments

Comments
 (0)