Skip to content

Commit 5b44c98

Browse files
authored
Fix clang tidy warnings (#105)
- fixed various clang-tidy warnings - fixed various gcc warnings - implemented missing noexcept specifications in some places to fix clang-tidy warnings
1 parent 38e376c commit 5b44c98

39 files changed

+367
-252
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/allocator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace {
1212
template <std::size_t Size>
1313
struct inline_resource : std::pmr::memory_resource {
1414
const char* name;
15-
explicit inline_resource(const char* name) : name(name) {}
15+
explicit inline_resource(const char* n) : name(n) {}
1616
std::byte buffer[Size]{}; // NOLINT(hicpp-avoid-c-arrays)
1717
std::byte* next{+this->buffer}; // NOLINT(hicpp-no-array-decay)
1818

@@ -39,13 +39,13 @@ struct allocator_aware_fun {
3939

4040
template <typename F>
4141
requires std::same_as<std::remove_cvref_t<F>, std::remove_cvref_t<Fun>>
42-
explicit allocator_aware_fun(F&& fun) : fun(std::forward<F>(fun)) {}
43-
allocator_aware_fun(const allocator_aware_fun& other, allocator_type allocator = {})
44-
: fun(other.fun), allocator(allocator) {}
42+
explicit allocator_aware_fun(F&& f) : fun(std::forward<F>(f)) {}
43+
allocator_aware_fun(const allocator_aware_fun& other, allocator_type alloc = {})
44+
: fun(other.fun), allocator(alloc) {}
4545
allocator_aware_fun(allocator_aware_fun&& other) noexcept
4646
: fun(std::move(other.fun)), allocator(other.allocator) {}
47-
allocator_aware_fun(allocator_aware_fun&& other, allocator_type allocator)
48-
: fun(std::move(other.fun)), allocator(allocator) {}
47+
allocator_aware_fun(allocator_aware_fun&& other, allocator_type alloc)
48+
: fun(std::move(other.fun)), allocator(alloc) {}
4949

5050
template <typename... Args>
5151
auto operator()(Args&&... args) noexcept {

examples/doc-just_error.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
#include <cassert>
77
namespace ex = beman::execution26;
88

9+
namespace {
10+
void use(auto&&...) {}
11+
} // namespace
12+
913
int main() {
1014
bool had_error{false};
1115
auto result = ex::sync_wait(ex::just_error(std::error_code(17, std::system_category())) |
1216
ex::upon_error([&](std::error_code ec) {
17+
use(ec);
1318
assert(ec.value() == 17);
1419
had_error = true;
1520
}));
21+
use(result, had_error);
22+
assert(result);
1623
assert(had_error);
1724
}

examples/doc-just_stopped.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
#include <iostream> //-dk:TODO remove
88
namespace ex = beman::execution26;
99

10+
namespace {
11+
void use(auto&&...) {}
12+
} // namespace
13+
1014
int main() {
1115
bool stopped{false};
1216

1317
auto result = ex::sync_wait(ex::just_stopped() | ex::upon_stopped([&] { stopped = true; }));
18+
use(result, stopped);
19+
assert(result);
1420
assert(stopped);
1521
}

examples/sender-demo.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ struct just_op_state {
1414
std::pmr::string value;
1515

1616
template <typename R>
17-
just_op_state(R&& r, std::pmr::string&& value)
18-
: rec(std::forward<R>(r)), value(std::move(value), ex::get_allocator(ex::get_env(rec))) {}
17+
just_op_state(R&& r, std::pmr::string&& val)
18+
: rec(std::forward<R>(r)), value(std::move(val), ex::get_allocator(ex::get_env(rec))) {}
1919

2020
void start() & noexcept { ex::set_value(std::move(rec), std::move(value)); }
2121
};
@@ -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/stopping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace {
2222
struct env {
2323
ex::inplace_stop_token token;
2424

25-
env(ex::inplace_stop_token token) : token(token) {} // NOLINT(hicpp-explicit-conversions)
25+
explicit env(ex::inplace_stop_token t) : token(t) {} // NOLINT(hicpp-explicit-conversions)
2626

2727
auto query(const ex::get_stop_token_t&) const noexcept { return this->token; }
2828
};
@@ -38,7 +38,7 @@ struct inject_cancel_sender {
3838
std::remove_cvref_t<Receiver> inner_receiver;
3939
ex::inplace_stop_token token{};
4040

41-
auto get_env() const noexcept -> env { return {this->token}; }
41+
auto get_env() const noexcept -> env { return env(this->token); }
4242

4343
template <typename... T>
4444
auto set_value(T&&... t) noexcept -> void {

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/basic_operation.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ template <typename Sender, typename Receiver>
3535
using inner_ops_t = ::beman::execution26::detail::connect_all_result<Sender, Receiver>;
3636
inner_ops_t inner_ops;
3737

38-
basic_operation(Sender&& sender, Receiver&& receiver) noexcept(true /*-dk:TODO*/)
38+
basic_operation(Sender&& sender, Receiver&& receiver) noexcept(
39+
noexcept(::beman::execution26::detail::basic_state<Sender, Receiver>(::std::forward<Sender>(sender),
40+
::std::move(receiver))) &&
41+
noexcept(::beman::execution26::detail::connect_all(this,
42+
::std::forward<Sender>(sender),
43+
::beman::execution26::detail::indices_for<Sender>())))
3944
: ::beman::execution26::detail::basic_state<Sender, Receiver>(::std::forward<Sender>(sender),
4045
::std::move(receiver)),
4146
// NOLINTBEGIN(bugprone-use-after-move,hicpp-invalid-access-moved)

0 commit comments

Comments
 (0)