Skip to content

Commit f3b66fc

Browse files
authored
Merge pull request #73 from beman-project/address-clang-tidy-reports
Address clang tidy reports
2 parents c9fb7b3 + fa09ca4 commit f3b66fc

23 files changed

+270
-164
lines changed

include/beman/execution26/detail/allocator_aware_move.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <beman/execution26/detail/product_type.hpp>
88
#include <beman/execution26/detail/get_allocator.hpp>
99
#include <beman/execution26/detail/get_env.hpp>
10+
#include <exception>
1011
#include <memory>
1112
#include <utility>
1213

@@ -20,16 +21,21 @@ template <typename T, typename Context>
2021
* \internal
2122
*/
2223
auto allocator_aware_move(T&& obj, Context&& context) noexcept -> decltype(auto) {
23-
if constexpr (requires { ::beman::execution26::get_allocator(::beman::execution26::get_env(context)); }) {
24-
if constexpr (decltype(::beman::execution26::detail::is_product_type(obj))()) {
25-
return obj.make_from(::beman::execution26::get_allocator(::beman::execution26::get_env(context)),
26-
::std::forward<T>(obj));
24+
try {
25+
if constexpr (requires { ::beman::execution26::get_allocator(::beman::execution26::get_env(context)); }) {
26+
if constexpr (decltype(::beman::execution26::detail::is_product_type(obj))()) {
27+
return obj.make_from(::beman::execution26::get_allocator(::beman::execution26::get_env(context)),
28+
::std::forward<T>(obj));
29+
} else {
30+
return ::std::make_obj_using_allocator<T>(
31+
::beman::execution26::get_allocator(::beman::execution26::get_env(context)),
32+
::std::forward<T>(obj));
33+
}
2734
} else {
28-
return ::std::make_obj_using_allocator<T>(
29-
::beman::execution26::get_allocator(::beman::execution26::get_env(context)), ::std::forward<T>(obj));
35+
return ::std::forward<T>(obj);
3036
}
31-
} else {
32-
return ::std::forward<T>(obj);
37+
} catch (...) {
38+
::std::terminate(); //-dk:TODO investigate if that can be avoided
3339
}
3440
}
3541
} // namespace beman::execution26::detail

include/beman/execution26/detail/product_type.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ struct product_type_base<::std::index_sequence<I...>, T...>
4848
}
4949
template <::std::size_t J>
5050
auto get() const& -> decltype(auto) {
51-
return this->element_get<J>(::std::move(*this));
51+
return this->element_get<J>(*this);
5252
}
5353

5454
template <::std::size_t J, typename Allocator, typename Self>
5555
static auto make_element(Allocator&& alloc, Self&& self) -> decltype(auto) {
56-
using type = ::std::remove_cvref_t<decltype(std::forward<Self>(self).template element_get<J>(
57-
std::forward<Self>(self)))>;
56+
using type = ::std::remove_cvref_t<decltype(product_type_base::element_get<J>(std::forward<Self>(self)))>;
5857
if constexpr (::std::uses_allocator_v<type, Allocator>)
59-
return ::std::make_obj_using_allocator<type>(
60-
alloc, std::forward<Self>(self).template element_get<J>(std::forward<Self>(self)));
58+
return ::std::make_obj_using_allocator<type>(alloc,
59+
product_type_base::element_get<J>(std::forward<Self>(self)));
6160
else
62-
return std::forward<Self>(self).template element_get<J>(std::forward<Self>(self));
61+
return product_type_base::element_get<J>(std::forward<Self>(self));
6362
}
6463

6564
auto operator==(const product_type_base&) const -> bool = default;
@@ -69,8 +68,7 @@ template <typename... T>
6968
struct product_type : ::beman::execution26::detail::product_type_base<::std::index_sequence_for<T...>, T...> {
7069
template <typename Allocator, typename Product, std::size_t... I>
7170
static auto make_from(Allocator&& allocator, Product&& product, std::index_sequence<I...>) -> product_type {
72-
return {
73-
::std::forward<Product>(product).template make_element<I>(allocator, ::std::forward<Product>(product))...};
71+
return {product_type::template make_element<I>(allocator, ::std::forward<Product>(product))...};
7472
}
7573

7674
template <typename Allocator, typename Product>

include/beman/execution26/detail/schedule_from.hpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ using as_tuple_t = typename as_tuple<T>::type;
6060
struct schedule_from_t {
6161
template <::beman::execution26::scheduler Scheduler, ::beman::execution26::sender Sender>
6262
auto operator()(Scheduler&& scheduler, Sender&& sender) const {
63-
auto domain{::beman::execution26::detail::query_with_default(::beman::execution26::get_domain,
64-
::std::forward<Scheduler>(scheduler),
65-
::beman::execution26::default_domain{})};
63+
auto domain{::beman::execution26::detail::query_with_default(
64+
::beman::execution26::get_domain, scheduler, ::beman::execution26::default_domain{})};
6665
return ::beman::execution26::transform_sender(
6766
domain,
6867
::beman::execution26::detail::make_sender(
@@ -78,15 +77,21 @@ struct impls_for<::beman::execution26::detail::schedule_from_t> : ::beman::execu
7877
State* state;
7978

8079
auto set_value() && noexcept -> void {
81-
::std::visit(
82-
[this]<typename Tuple>(Tuple& result) noexcept -> void {
83-
if constexpr (not::std::same_as<::std::monostate, Tuple>) {
84-
::std::apply([this](auto&& tag,
85-
auto&&... args) { tag(std::move(state->receiver), std::move(args)...); },
86-
result);
87-
}
88-
},
89-
state->async_result);
80+
try {
81+
::std::visit(
82+
[this]<typename Tuple>(Tuple& result) noexcept -> void {
83+
if constexpr (not::std::same_as<::std::monostate, Tuple>) {
84+
::std::apply(
85+
[this](auto&& tag, auto&&... args) {
86+
tag(::std::move(this->state->receiver), ::std::move(args)...);
87+
},
88+
result);
89+
}
90+
},
91+
state->async_result);
92+
} catch (...) {
93+
::beman::execution26::set_error(::std::move(state->receiver), ::std::current_exception());
94+
}
9095
}
9196

9297
template <typename Error>

include/beman/execution26/detail/when_all.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,17 @@ struct impls_for<::beman::execution26::detail::when_all_t> : ::beman::execution2
136136
} break;
137137
case disposition::error:
138138
this->on_stop.reset();
139-
::std::visit(
140-
[&]<typename Error>(Error& error) noexcept {
141-
if constexpr (!::std::same_as<Error, nonesuch>) {
142-
::beman::execution26::set_error(::std::move(receiver), ::std::move(error));
143-
}
144-
},
145-
this->errors);
139+
try {
140+
::std::visit(
141+
[&]<typename Error>(Error& error) noexcept {
142+
if constexpr (!::std::same_as<Error, nonesuch>) {
143+
::beman::execution26::set_error(::std::move(receiver), ::std::move(error));
144+
}
145+
},
146+
this->errors);
147+
} catch (...) {
148+
::beman::execution26::set_error(::std::move(receiver), ::std::current_exception());
149+
}
146150
break;
147151
case disposition::stopped:
148152
this->on_stop.reset();

include/beman/execution26/detail/with_await_transform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ----------------------------------------------------------------------------
1212

1313
namespace beman::execution26::detail {
14+
// NOLINTBEGIN(bugprone-crtp-constructor-accessibility)
1415
template <typename Derived>
1516
struct with_await_transform {
1617
template <typename T>
@@ -24,6 +25,7 @@ struct with_await_transform {
2425
return ::std::forward<T>(obj).as_awaitable(static_cast<Derived&>(*this));
2526
}
2627
};
28+
// NOLINTEND(bugprone-crtp-constructor-accessibility)
2729
} // namespace beman::execution26::detail
2830

2931
// ----------------------------------------------------------------------------

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ TEST(exec_fwd_env) {
5252
static_assert(test_std::forwarding_query(dynamic_query()));
5353
static_assert(test_std::forwarding_query(dynamic_query{true}));
5454
static_assert(not test_std::forwarding_query(dynamic_query{false}));
55+
// NOLINTNEXTLINE(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
5556
ASSERT(test_std::forwarding_query(dynamic_query{true}));
57+
// NOLINTNEXTLINE(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
5658
ASSERT(not test_std::forwarding_query(dynamic_query{false}));
5759
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ struct error {
1616

1717
struct non_movable {
1818
non_movable(non_movable&&) = delete;
19+
non_movable(const non_movable&) = delete;
20+
~non_movable() = default;
21+
auto operator=(non_movable&&) -> non_movable& = delete;
22+
auto operator=(const non_movable&) -> non_movable& = delete;
1923
};
2024
struct non_copyable {
2125
non_copyable(non_copyable&&) = default;
2226
non_copyable(const non_copyable&) = delete;
27+
~non_copyable() = default;
28+
auto operator=(non_copyable&&) -> non_copyable& = default;
29+
auto operator=(const non_copyable&) -> non_copyable& = delete;
2330
};
2431

2532
auto test_movable_value() -> void {
@@ -63,6 +70,7 @@ auto test_as_except_ptr() -> void {
6370
} catch (error& e) {
6471
ASSERT(e.value == 17);
6572
} catch (...) {
73+
// NOLINTNEXTLINE(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
6674
ASSERT(nullptr == "wrong exception type produced by as_except_ptr for random error");
6775
}
6876

@@ -73,6 +81,7 @@ auto test_as_except_ptr() -> void {
7381
} catch (std::system_error& e) {
7482
ASSERT(e.code() == errc);
7583
} catch (...) {
84+
// NOLINTNEXTLINE(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
7685
ASSERT(nullptr == "wrong exception type produced by as_except_ptr for error code");
7786
}
7887
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
namespace {
1212
struct with_non_env;
1313
struct non_env {
14+
non_env(non_env&&) = delete;
15+
non_env(const non_env&) = delete;
16+
auto operator=(non_env&&) -> non_env& = delete;
17+
auto operator=(const non_env&) -> non_env& = delete;
18+
1419
private:
1520
friend struct with_non_env;
16-
non_env() = default;
17-
non_env(non_env&&) = delete;
21+
non_env() = default;
1822
~non_env() = default;
1923
};
2024
struct with_non_env {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
namespace {
1818
struct not_movable {
1919
not_movable() = default;
20+
not_movable(const not_movable&) = delete;
2021
not_movable(not_movable&&) = delete;
22+
~not_movable() = default;
23+
auto operator=(const not_movable&) -> not_movable& = delete;
24+
auto operator=(not_movable&&) -> not_movable& = delete;
2125
};
2226
template <bool Expect, typename Completion, typename CPO, typename... T>
2327
auto test_just_constraints(CPO const& cpo, T&&... args) -> void {
@@ -60,7 +64,7 @@ auto test_just_constraints() -> void {
6064
template <typename... T>
6165
struct value_receiver {
6266
using receiver_concept = test_std::receiver_t;
63-
bool* called;
67+
bool* called{};
6468
test_detail::product_type<std::decay_t<T>...> expect{};
6569

6670
template <typename... A>
@@ -206,7 +210,7 @@ TEST(exec_just) {
206210
test_just();
207211
test_just_allocator();
208212
} catch (...) {
209-
ASSERT(nullptr ==
210-
"the just tests shouldn't throw"); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
213+
// NOLINTNEXTLINE(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
214+
ASSERT(nullptr == "the just tests shouldn't throw");
211215
}
212216
}

tests/beman/execution26/exec-opstate-start.test.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,68 @@
1010

1111
namespace {
1212
struct receiver {
13-
int value{};
13+
int& value;
1414
auto set_value(int value) && noexcept -> void { this->value = value; }
1515
};
1616

17-
struct non_opstate {};
17+
struct non_opstate {
18+
receiver rcvr;
19+
};
1820

1921
template <bool Noexcept>
2022
struct opstate {
21-
receiver* rcvr;
22-
auto start() const noexcept(Noexcept) -> void { test_std::set_value(::std::move(*rcvr), 42); }
23+
receiver rcvr;
24+
auto start() const noexcept(Noexcept) -> void { test_std::set_value(receiver(this->rcvr.value), 42); }
2325
};
2426

2527
template <typename State>
2628
auto test_start_argument_type() {
27-
receiver rcvr{};
28-
State state{&rcvr};
29-
receiver crcvr{};
30-
const State cstate{&crcvr};
29+
int value{};
30+
State state{receiver{value}};
31+
int cvalue{};
32+
const State cstate{receiver{cvalue}};
3133

3234
static_assert(requires { test_std::start(state); });
3335
static_assert(requires { test_std::start(cstate); });
3436

35-
static_assert(not requires { test_std::start(State(&rcvr)); });
37+
static_assert(not requires { test_std::start(State(receiver{value})); });
3638
static_assert(not requires { test_std::start(std::move(state)); });
3739
static_assert(not requires { test_std::start(std::move(cstate)); });
3840
}
3941

4042
template <typename State>
4143
auto test_start_member() {
42-
State state{};
44+
int value{};
45+
State state{receiver{value}};
4346
static_assert(not requires { test_std::start(state); });
44-
State cstate{};
47+
const State cstate{receiver{value}};
4548
static_assert(not requires { test_std::start(cstate); });
4649
}
4750

4851
template <typename State>
4952
auto test_start_noexcept() {
50-
State state{};
53+
int value{};
54+
State state{receiver{value}};
5155
static_assert(noexcept(state));
52-
State cstate{};
56+
int cvalue{};
57+
const State cstate{receiver{cvalue}};
5358
static_assert(noexcept(cstate));
5459
}
5560

5661
template <typename State>
5762
auto test_start_call() {
58-
receiver rcvr{};
59-
State state{&rcvr};
60-
receiver crcvr{};
61-
const State cstate{&crcvr};
63+
int value{};
64+
State state{receiver{value}};
65+
int cvalue{};
66+
const State cstate{receiver{cvalue}};
6267

63-
ASSERT(rcvr.value == 0);
68+
ASSERT(value == 0);
6469
test_std::start(state);
65-
ASSERT(rcvr.value == 42);
70+
ASSERT(value == 42);
6671

67-
ASSERT(crcvr.value == 0);
72+
ASSERT(cvalue == 0);
6873
test_std::start(cstate);
69-
ASSERT(crcvr.value == 42);
74+
ASSERT(cvalue == 42);
7075
}
7176
} // namespace
7277

0 commit comments

Comments
 (0)