Skip to content

Commit bc6a99a

Browse files
authored
Merge pull request #78 from ClausKlein/feature/prevent-more-clang-tidy-warnings
Fix cmake-tidy warnings on examples too
2 parents 6f00555 + 3a2a7be commit bc6a99a

File tree

10 files changed

+86
-40
lines changed

10 files changed

+86
-40
lines changed

.github/workflows/linux.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- "include/**"
1111
- "src/**"
1212
- "test/**"
13+
- "cmake/**"
14+
- "Makefile"
15+
- "CMakePresets.json"
1316
- "CMakeLists.txt"
1417
- ".github/workflows/linux.yml"
1518
pull_request:
@@ -18,6 +21,9 @@ on:
1821
- "include/**"
1922
- "src/**"
2023
- "test/**"
24+
- "cmake/**"
25+
- "Makefile"
26+
- "CMakePresets.json"
2127
- "CMakeLists.txt"
2228
- ".github/workflows/linux.yml"
2329

@@ -28,8 +34,8 @@ jobs:
2834
fail-fast: false
2935

3036
matrix:
31-
# TODO: sanitizer: [debug, release, asan, usan, tsan]
32-
sanitizer: [debug, release]
37+
# TODO: sanitizer: [debug, release, asan, usan, tsan, lsan, msan]
38+
preset: [debug, release]
3339
compiler: [g++-14, clang++-19]
3440

3541
steps:
@@ -42,5 +48,8 @@ jobs:
4248
chmod +x llvm.sh
4349
sudo ./llvm.sh 19 all
4450
45-
- name: Linux ${{ matrix.compiler }} ${{ matrix.sanitizer }}
46-
run: CXX=${{ matrix.compiler }} make ${{ matrix.sanitizer }}
51+
- name: Linux ${{ matrix.compiler }} ${{ matrix.preset }}
52+
run: CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}
53+
54+
- name: Linux ${{ matrix.compiler }} sanitizer
55+
run: CXX=${{ matrix.compiler }} make all

.github/workflows/macos.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- "include/**"
1111
- "src/**"
1212
- "test/**"
13+
- "cmake/**"
14+
- "Makefile"
15+
- "CMakePresets.json"
1316
- "CMakeLists.txt"
1417
- ".github/workflows/macos.yml"
1518
pull_request:
@@ -18,6 +21,9 @@ on:
1821
- "include/**"
1922
- "src/**"
2023
- "test/**"
24+
- "cmake/**"
25+
- "Makefile"
26+
- "CMakePresets.json"
2127
- "CMakeLists.txt"
2228
- ".github/workflows/macos.yml"
2329

@@ -28,7 +34,7 @@ jobs:
2834
fail-fast: false
2935

3036
matrix:
31-
sanitizer: [debug, release]
37+
preset: [debug, release]
3238
# TODO: compiler: [g++, clang++-19]
3339
compiler: [g++, clang++-18]
3440

@@ -49,10 +55,19 @@ jobs:
4955
run: |
5056
brew install llvm@19 || echo ignored
5157
52-
- name: macos clang++-18 ${{ matrix.sanitizer }}
58+
- name: macos clang++-18 ${{ matrix.preset }}
5359
if: startsWith(matrix.compiler, 'clang')
54-
run: CXX=$(brew --prefix llvm@18)/bin/clang++ make ${{ matrix.sanitizer }}
60+
run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}
5561

56-
- name: macos g++ ${{ matrix.sanitizer }}
62+
- name: macos clang++-18 sanitizer
63+
if: startsWith(matrix.compiler, 'clang')
64+
run: CXX=$(brew --prefix llvm@18)/bin/clang++ make all
65+
66+
- name: macos g++ ${{ matrix.preset }}
5767
if: startsWith(matrix.compiler, 'g++')
58-
run: CXX=${{ matrix.compiler }} make ${{ matrix.sanitizer }}
68+
run: CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}
69+
70+
# TODO: fails with AppleClang 16.0.0 on CI!
71+
# - name: macos g++ sanitizer
72+
# if: startsWith(matrix.compiler, 'g++')
73+
# run: CXX=${{ matrix.compiler }} make all

.github/workflows/windows.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
- "include/**"
1111
- "src/**"
1212
- "test/**"
13+
- "cmake/**"
14+
- "CMakePresets.json"
1315
- "CMakeLists.txt"
1416
- ".github/workflows/windows.yml"
1517
pull_request:
@@ -18,6 +20,8 @@ on:
1820
- "include/**"
1921
- "src/**"
2022
- "test/**"
23+
- "cmake/**"
24+
- "CMakePresets.json"
2125
- "CMakeLists.txt"
2226
- ".github/workflows/windows.yml"
2327

Makefile

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
# Makefile
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
SANITIZERS = release debug msan asan usan tsan
4+
MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules.
5+
MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced.
6+
7+
SANITIZERS = release debug usan # TODO: lsan
8+
OS := $(shell /usr/bin/uname)
9+
ifeq ($(OS),Darwin)
10+
SANITIZERS += tsan
11+
endif
12+
ifeq ($(OS),Linux)
13+
SANITIZERS += asan # TODO: msan
14+
endif
515

616
.PHONY: default doc run update check ce todo distclean clean codespell clang-tidy build test all format $(SANITIZERS)
717

8-
COMPILER=system
18+
SYSROOT ?=
19+
TOOLCHAIN ?=
20+
21+
COMPILER=c++
922
CXX_BASE=$(CXX:$(dir $(CXX))%=%)
1023
ifeq ($(CXX_BASE),g++)
11-
COMPILER=gcc
24+
COMPILER=g++
1225
endif
1326
ifeq ($(CXX_BASE),clang++)
14-
COMPILER=clang
27+
COMPILER=clang++
1528
endif
1629

1730
CXX_FLAGS = -g
@@ -20,11 +33,10 @@ SOURCEDIR = $(CURDIR)
2033
BUILDROOT = build
2134
BUILD = $(BUILDROOT)/$(SANITIZER)
2235
EXAMPLE = beman.execution26.examples.stop_token
23-
CMAKE_C_COMPILER=$(COMPILER)
2436
CMAKE_CXX_COMPILER=$(COMPILER)
2537

2638
ifeq ($(SANITIZER),release)
27-
CXX_FLAGS = -O3 -pedantic -Wall -Wextra -Werror
39+
CXX_FLAGS = -O3 -Wpedantic -Wall -Wextra -Wshadow # TODO: -Werror
2840
endif
2941
ifeq ($(SANITIZER),debug)
3042
CXX_FLAGS = -g
@@ -62,11 +74,12 @@ $(SANITIZERS):
6274

6375
build:
6476
@mkdir -p $(BUILD)
65-
cd $(BUILD); CC=$(CXX) cmake $(SOURCEDIR) $(TOOLCHAIN) $(SYSROOT) -DCMAKE_CXX_COMPILER=$(CXX) -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
77+
cd $(BUILD); CC=$(CXX) cmake -G Ninja $(SOURCEDIR) $(TOOLCHAIN) $(SYSROOT) -DCMAKE_CXX_COMPILER=$(CXX) -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
6678
cmake --build $(BUILD)
6779

68-
test:
69-
cmake --workflow --preset $(SANITIZER)
80+
test: build
81+
# cmake --workflow --preset $(SANITIZER)
82+
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure
7083

7184
ce:
7285
@mkdir -p $(BUILD)
@@ -83,8 +96,9 @@ check:
8396
< $$h sed -n "/^ *# *include <Beman\//s@.*[</]Beman/\(.*\).hpp>.*@$$from \1@p"; \
8497
done | tsort > /dev/null
8598

99+
build/$(SANITIZER)/compile_commands.json: $(SANITIZER)
86100
clang-tidy: build/$(SANITIZER)/compile_commands.json
87-
run-clang-tidy -p build/$(SANITIZER) tests
101+
run-clang-tidy -p build/$(SANITIZER) tests examples
88102

89103
codespell:
90104
codespell -L statics,snd,copyable,cancelled
@@ -105,7 +119,7 @@ clean-doc:
105119
$(RM) -r docs/html docs/latex
106120

107121
clean: clean-doc
108-
$(RM) -r $(BUILD)
122+
$(RM) -r $(BUILD)
109123
$(RM) mkerr olderr *~
110124

111125
distclean: clean

examples/allocator.cpp

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

1919
void* do_allocate(std::size_t size, std::size_t) override {
2020
std::cout << "allocating from=" << this->name << ", size=" << size << "\n";
@@ -29,6 +29,7 @@ struct inline_resource : std::pmr::memory_resource {
2929
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; }
3030
};
3131

32+
// NOLINTBEGIN(hicpp-special-member-functions)
3233
template <typename Fun>
3334
struct allocator_aware_fun {
3435
using allocator_type = std::pmr::polymorphic_allocator<>;
@@ -38,10 +39,11 @@ struct allocator_aware_fun {
3839

3940
template <typename F>
4041
requires std::same_as<std::remove_cvref_t<F>, std::remove_cvref_t<Fun>>
41-
allocator_aware_fun(F&& fun) : fun(std::forward<F>(fun)) {}
42+
explicit allocator_aware_fun(F&& fun) : fun(std::forward<F>(fun)) {}
4243
allocator_aware_fun(const allocator_aware_fun& other, allocator_type allocator = {})
4344
: fun(other.fun), allocator(allocator) {}
44-
allocator_aware_fun(allocator_aware_fun&& other) : fun(std::move(other.fun)), allocator(other.allocator) {}
45+
allocator_aware_fun(allocator_aware_fun&& other) noexcept
46+
: fun(std::move(other.fun)), allocator(other.allocator) {}
4547
allocator_aware_fun(allocator_aware_fun&& other, allocator_type allocator)
4648
: fun(std::move(other.fun)), allocator(allocator) {}
4749

@@ -50,6 +52,7 @@ struct allocator_aware_fun {
5052
return this->fun(this->allocator, std::forward<Args>(args)...);
5153
}
5254
};
55+
// NOLINTEND(hicpp-special-member-functions)
5356
template <typename Fun>
5457
allocator_aware_fun(Fun&& fun) -> allocator_aware_fun<Fun>;
5558

@@ -60,7 +63,7 @@ struct allocator_env {
6063
} // namespace
6164

6265
auto main() -> int {
63-
int values[] = {1, 2, 3};
66+
int values[] = {1, 2, 3}; // NOLINT(hicpp-avoid-c-arrays)
6467
auto s{ex::just(std::span(values)) | ex::let_value(allocator_aware_fun([](auto alloc, std::span<int> v) {
6568
return ex::just(std::pmr::vector<int>(v.begin(), v.end(), alloc));
6669
})) |

examples/playground.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ namespace ex = ::beman::execution26;
1212

1313
int main()
1414
{
15-
auto[result] = ex::sync_wait(
16-
ex::when_all(
17-
ex::just(std::string("hello, ")),
18-
ex::just(std::string("world"))
19-
) | ex::then([](auto s1, auto s2){ return s1 + s2; })
20-
).value_or(std::tuple(std::string("oops")));
15+
auto [result] = ex::sync_wait(ex::when_all(ex::just(std::string("hello, ")), ex::just(std::string("world"))) |
16+
ex::then([](const auto& s1, const auto& s2) { return s1 + s2; }))
17+
.value_or(std::tuple(std::string("oops")));
2118
std::cout << "result='" << result << "'\n";
2219
}

examples/sender-demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static_assert(ex::sender_in<just_sender<std::pmr::string>>);
4747

4848
int main() {
4949
auto j = just_sender{std::pmr::string("value")};
50-
auto t = std::move(j) | ex::then([](std::pmr::string v) { return v + " then"; });
50+
auto t = std::move(j) | ex::then([](const std::pmr::string& v) { return v + " then"; });
5151
auto w = ex::when_all(std::move(t));
5252
auto e = ex::detail::write_env(std::move(w),
5353
ex::detail::make_env(ex::get_allocator, std::pmr::polymorphic_allocator<>()));

examples/stop_token.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ namespace exec = beman::execution26;
4545
// doesn't seem to be readily enabled on MacOS.
4646
// - std::print isn't available everywhere, yet. Let's try a simple
4747
// placeholder.
48-
static ::std::mutex io_lock;
48+
namespace {
49+
::std::mutex io_lock;
4950
void print(std::string_view text, auto&&...) {
50-
std::lock_guard guard(io_lock);
51+
const std::lock_guard guard(io_lock);
5152
::std::cout << text;
5253
}
5354

5455
template <typename Token>
55-
auto active(Token token) -> void {
56+
auto active(const Token& token) -> void {
5657
auto i{0ull};
5758
while (not token.stop_requested()) {
5859
// do work
@@ -69,9 +70,9 @@ struct stop_callback_for_t {
6970

7071
#ifdef __cpp_lib_latch
7172
template <typename Token>
72-
auto inactive(Token token) -> void {
73+
auto inactive(const Token& token) -> void {
7374
::std::latch latch(1);
74-
stop_callback_for_t cb(token, [&latch] { latch.count_down(); });
75+
const stop_callback_for_t cb(token, [&latch] { latch.count_down(); });
7576

7677
latch.wait();
7778
print("inactive thread done (latch)\n");
@@ -88,6 +89,7 @@ auto inactive(Token token) -> void {
8889
print("inactive thread done (condition_variable)\n");
8990
}
9091
#endif
92+
} // namespace
9193

9294
auto main() -> int {
9395
exec::stop_source source;

examples/stopping.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ namespace ex = beman::execution26;
1818

1919
// ----------------------------------------------------------------------------
2020

21+
namespace {
2122
struct env {
2223
ex::inplace_stop_token token;
2324

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

2627
auto query(const ex::get_stop_token_t&) const noexcept { return this->token; }
2728
};
@@ -73,6 +74,7 @@ struct receiver {
7374
auto set_error(auto&&) noexcept -> void {}
7475
auto set_stopped() noexcept -> void {}
7576
};
77+
} // namespace
7678

7779
int main() {
7880
ex::inplace_stop_source source;

examples/when_all-cancel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct eager {
109109
state(R&& r, S&& s) : outer_receiver(std::forward<R>(r)), inner_state() {
110110
inner_state.emplace(std::forward<S>(s), receiver{this});
111111
}
112+
// TODO on next line: bugprone-unchecked-optional-access
112113
auto start() & noexcept -> void { ex::start((*this->inner_state).st); }
113114
};
114115
template <ex::receiver Receiver>
@@ -127,7 +128,6 @@ auto main() -> int {
127128

128129
ex::inplace_stop_source source{};
129130
auto op{ex::connect(s, receiver{&source})};
130-
(void)op;
131131
std::cout << "start\n";
132132
ex::start(op);
133133
std::cout << "started\n";

0 commit comments

Comments
 (0)