Skip to content

Commit 4c701ed

Browse files
committed
address another helping of clang-tidy reports
1 parent 38e376c commit 4c701ed

16 files changed

+75
-43
lines changed

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SANITIZERS := run
1414
# SANITIZERS += asan # TODO: tsan msan
1515
# endif
1616

17-
.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format $(SANITIZERS)
17+
.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format unstage $(SANITIZERS)
1818

1919
SYSROOT ?=
2020
TOOLCHAIN ?=
@@ -79,6 +79,7 @@ doc:
7979

8080
build:
8181
CC=$(CXX) cmake --fresh -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
82+
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
8283
-DCMAKE_CXX_COMPILER=$(CXX) # XXX -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
8384
cmake --build $(BUILD)
8485

@@ -111,8 +112,8 @@ check:
111112
done | tsort > /dev/null
112113

113114
build/$(SANITIZER)/compile_commands.json: $(SANITIZER)
114-
clang-tidy: build/$(SANITIZER)/compile_commands.json
115-
run-clang-tidy -p build/$(SANITIZER) tests examples
115+
clang-tidy: $(BUILD)/compile_commands.json
116+
run-clang-tidy -p $(BUILD) tests examples
116117

117118
codespell:
118119
codespell -L statics,snd,copyable,cancelled
@@ -128,6 +129,9 @@ clang-format:
128129
todo:
129130
bin/mk-todo.py
130131

132+
unstage:
133+
git restore --staged tests/beman/execution26/CMakeLists.txt
134+
131135
.PHONY: clean-doc
132136
clean-doc:
133137
$(RM) -r docs/html docs/latex

examples/doc-just_error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ int main() {
1313
assert(ec.value() == 17);
1414
had_error = true;
1515
}));
16+
assert(result);
1617
assert(had_error);
1718
}

examples/doc-just_stopped.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ int main() {
1111
bool stopped{false};
1212

1313
auto result = ex::sync_wait(ex::just_stopped() | ex::upon_stopped([&] { stopped = true; }));
14+
assert(result);
1415
assert(stopped);
1516
}

examples/sender-demo.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,22 @@ static_assert(ex::sender<just_sender<std::pmr::string>>);
4646
static_assert(ex::sender_in<just_sender<std::pmr::string>>);
4747

4848
int main() {
49-
auto j = just_sender{std::pmr::string("value")};
50-
auto t = std::move(j) | ex::then([](const std::pmr::string& v) { return v + " then"; });
51-
auto w = ex::when_all(std::move(t));
52-
auto e = ex::detail::write_env(std::move(w),
53-
ex::detail::make_env(ex::get_allocator, std::pmr::polymorphic_allocator<>()));
54-
55-
std::cout << "before start\n";
56-
auto r = ex::sync_wait(std::move(e));
57-
if (r) {
58-
auto [v] = *r;
59-
std::cout << "produced='" << v << "'\n";
60-
} else
61-
std::cout << "operation was cancelled\n";
62-
std::cout << "after start\n";
49+
try {
50+
auto j = just_sender{std::pmr::string("value")};
51+
auto t = std::move(j) | ex::then([](const std::pmr::string& v) { return v + " then"; });
52+
auto w = ex::when_all(std::move(t));
53+
auto e = ex::detail::write_env(std::move(w),
54+
ex::detail::make_env(ex::get_allocator, std::pmr::polymorphic_allocator<>()));
55+
56+
std::cout << "before start\n";
57+
auto r = ex::sync_wait(std::move(e));
58+
if (r) {
59+
auto [v] = *r;
60+
std::cout << "produced='" << v << "'\n";
61+
} else
62+
std::cout << "operation was cancelled\n";
63+
std::cout << "after start\n";
64+
} catch (const std::exception& ex) {
65+
std::cout << "ERROR: " << ex.what() << "\n";
66+
}
6367
}

examples/stop_token.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <beman/execution26/stop_token.hpp>
55
#include <condition_variable>
66
#include <iostream>
7+
#include <exception>
78
#include <latch>
89
#include <mutex>
910
#include <thread>
@@ -92,15 +93,20 @@ auto inactive(Token token) -> void {
9293
} // namespace
9394

9495
auto main() -> int {
95-
exec::stop_source source;
96-
::std::thread act([token = source.get_token()] { active(token); });
97-
::std::thread inact([token = source.get_token()] { inactive(token); });
96+
try {
9897

99-
print("threads started\n");
100-
source.request_stop();
101-
print("threads cancelled\n");
98+
exec::stop_source source;
99+
::std::thread act([token = source.get_token()] { active(token); });
100+
::std::thread inact([token = source.get_token()] { inactive(token); });
102101

103-
act.join();
104-
inact.join();
105-
print("done\n");
102+
print("threads started\n");
103+
source.request_stop();
104+
print("threads cancelled\n");
105+
106+
act.join();
107+
inact.join();
108+
print("done\n");
109+
} catch (const std::exception& ex) {
110+
std::cout << "ERROR: " << ex.what() << "\n";
111+
}
106112
}

examples/when_all-cancel.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <optional>
88
#include <type_traits>
99
#include <utility>
10+
#include <cassert>
1011

1112
namespace ex = beman::execution26;
1213

@@ -106,11 +107,15 @@ struct eager {
106107
std::optional<helper> inner_state;
107108

108109
template <typename R, typename S>
109-
state(R&& r, S&& s) : outer_receiver(std::forward<R>(r)), inner_state() {
110-
inner_state.emplace(std::forward<S>(s), receiver{this});
110+
state(R&& r, S&& s)
111+
: outer_receiver(std::forward<R>(r)), inner_state(std::in_place, std::forward<S>(s), receiver{this}) {}
112+
auto start() & noexcept -> void {
113+
if (this->inner_state) {
114+
ex::start((*this->inner_state).st);
115+
} else {
116+
assert(this->inner_state);
117+
}
111118
}
112-
// TODO on next line: bugprone-unchecked-optional-access
113-
auto start() & noexcept -> void { ex::start((*this->inner_state).st); }
114119
};
115120
template <ex::receiver Receiver>
116121
auto connect(Receiver&& receiver) {

include/beman/execution26/detail/as_awaitable.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_AS_AWAITABLE
55
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_AS_AWAITABLE
66

7-
#include <beman/execution26/detail/as_awaitable.hpp>
87
#include <beman/execution26/detail/awaitable_sender.hpp>
98
#include <beman/execution26/detail/is_awaitable.hpp>
109
#include <beman/execution26/detail/sender_awaitable.hpp>
@@ -31,12 +30,11 @@ struct as_awaitable_t {
3130
"as_awaitable must return an awaitable");
3231
return ::std::forward<Expr>(expr).as_awaitable(promise);
3332
} else if constexpr (::beman::execution26::detail::
34-
is_awaitable<Expr, ::beman::execution26::detail::unspecified_promise>) {
33+
is_awaitable<Expr, ::beman::execution26::detail::unspecified_promise> ||
34+
not::beman::execution26::detail::awaitable_sender<Expr, Promise>) {
3535
return ::std::forward<Expr>(expr);
36-
} else if constexpr (::beman::execution26::detail::awaitable_sender<Expr, Promise>) {
37-
return ::beman::execution26::detail::sender_awaitable<Expr, Promise>{::std::forward<Expr>(expr), promise};
3836
} else {
39-
return ::std::forward<Expr>(expr);
37+
return ::beman::execution26::detail::sender_awaitable<Expr, Promise>{::std::forward<Expr>(expr), promise};
4038
}
4139
}
4240
};

include/beman/execution26/detail/inplace_stop_source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class beman::execution26::inplace_stop_callback final
8686
inplace_stop_callback(::beman::execution26::inplace_stop_token, Init&&);
8787
inplace_stop_callback(const inplace_stop_callback&) = delete;
8888
inplace_stop_callback(inplace_stop_callback&&) = delete;
89-
~inplace_stop_callback() {
89+
~inplace_stop_callback() override {
9090
if (this->source) {
9191
this->source->deregister(this);
9292
}

include/beman/execution26/detail/run_loop.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class run_loop {
3939
};
4040

4141
struct opstate_base : ::beman::execution26::detail::virtual_immovable {
42-
virtual ~opstate_base() = default;
42+
// virtual ~opstate_base() override = default;
4343
opstate_base* next{};
4444
virtual auto execute() noexcept -> void = 0;
4545
};

include/beman/execution26/detail/sender_awaitable.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_SENDER_AWAITABLE
55
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SENDER_AWAITABLE
66

7-
#include <beman/execution26/detail/as_awaitable.hpp>
87
#include <beman/execution26/detail/as_except_ptr.hpp>
98
#include <beman/execution26/detail/connect_result_t.hpp>
109
#include <beman/execution26/detail/connect.hpp>

0 commit comments

Comments
 (0)