Skip to content

Commit e207b08

Browse files
author
Dmitry Malakhov
committed
clang-tidy checks + fixes for them
1 parent 700f61b commit e207b08

36 files changed

+170
-117
lines changed

.clang-format

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
2-
31
BasedOnStyle: LLVM
42
ColumnLimit: 100
53
BreakTemplateDeclarations: Yes
64
AllowShortFunctionsOnASingleLine: None
5+
IncludeBlocks: Regroup

.clang-tidy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Checks: >
2+
performance-*,
3+
-performance-enum-size,
4+
bugprone-*,
5+
-bugprone-easily-swappable-parameters,
6+
modernize-*,
7+
-modernize-use-trailing-return-type,
8+
portability-*,
9+
readability-*,
10+
-readability-identifier-length,
11+
-readability-static-accessed-through-instance,
12+
-readability-make-member-function-const,
13+
-readability-avoid-return-with-void-value,
14+
-readability-named-parameter,
15+
16+
17+
# Turn all the warnings from the checks above into errors.
18+
WarningsAsErrors: "*"
19+
20+
CheckOptions:
21+
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
22+
- { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE }
23+
- { key: readability-identifier-naming.LocalConstantCase, value: lower_case }
24+
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
25+
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
26+
- { key: readability-identifier-naming.StructCase, value: CamelCase }
27+
- { key: readability-identifier-naming.TemplateParameterCase, value: UPPER_CASE }
28+
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
29+
- { key: readability-identifier-naming.VariableCase, value: lower_case }
30+
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
31+
- { key: readability-identifier-naming.ProtectedMemberPrefix, value: m_ }
32+
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
33+
- { key: readability-identifier-naming.LocalVariableCase, value: lower_case }

.github/workflows/Codestyle.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Codestyle"
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
check-codestyle:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: cachix/install-nix-action@v26
13+
- uses: cachix/cachix-action@v14
14+
with:
15+
name: devenv
16+
17+
- name: devenv.sh install
18+
run: nix profile install nixpkgs#devenv
19+
20+
- name: devenv.sh evaluation
21+
run: devenv shell echo
22+
23+
- name: clang-format checks
24+
run: devenv shell "find . -type f \( -name \*.cpp -o -name \*.hpp \) -print0 | xargs -0 -n1 -P$(nproc) clang-format --Werror -n"
25+
26+
- name: clang-tidy checks
27+
run: devenv shell "find include src -type f \( -name \*.cpp -o -name \*.hpp \) -print0 | xargs -0 -n1 -P$(nproc) clang-tidy -p build"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: "Test"
1+
name: "TestUbuntu"
22

33
on:
44
pull_request:
55
push:
66

77
jobs:
8-
linux-build-and-test:
8+
ubuntu-build-and-test:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build
44
.devenv*
55
devenv.local.nix
66
.direnv
7+
.clangd
78
compile_commands.json
89

910
.zed

devenv.nix

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# https://devenv.sh/
22
{ pkgs, ... }: {
3-
packages = with pkgs; [
4-
llvmPackages_latest.clang-tools
5-
xmake
6-
gdb
7-
];
3+
packages = with pkgs; [ llvmPackages_latest.clang-tools xmake gdb ];
84

95
languages.cplusplus.enable = true;
106
languages.nix.enable = true;

include/corosig/Alloc.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#pragma once
22

3-
#include <algorithm>
43
#include <array>
5-
#include <bit>
64
#include <cassert>
75
#include <cstddef>
8-
#include <limits>
9-
#include <span>
106

117
namespace corosig {
128

@@ -30,7 +26,7 @@ struct Alloc {
3026

3127
struct AllocationHeader {
3228
size_t block_size = 0;
33-
char padding;
29+
size_t padding = 0;
3430
};
3531

3632
using Node = typename FreeList::Node;
@@ -53,10 +49,10 @@ struct Alloc {
5349

5450
template <size_t SIZE>
5551
Alloc(Memory<SIZE> &mem) noexcept : m_mem{mem.begin()}, m_mem_size{mem.size()} {
56-
Node *firstNode = new (m_mem) Node{};
57-
firstNode->data.block_size = SIZE - sizeof(Node);
58-
firstNode->next = nullptr;
59-
m_free_list.insert(nullptr, firstNode);
52+
Node *first_node = new (m_mem) Node{};
53+
first_node->data.block_size = SIZE - sizeof(Node);
54+
first_node->next = nullptr;
55+
m_free_list.insert(nullptr, first_node);
6056
}
6157

6258
Alloc(const Alloc &) = delete;
@@ -65,21 +61,21 @@ struct Alloc {
6561
Alloc &operator=(Alloc &&) noexcept;
6662
~Alloc();
6763

68-
size_t peak_memory() noexcept {
64+
[[nodiscard]] size_t peak_memory() const noexcept {
6965
return m_peak;
7066
}
7167

72-
size_t current_memory() noexcept {
68+
[[nodiscard]] size_t current_memory() const noexcept {
7369
return m_peak;
7470
}
7571

76-
void *allocate(size_t size, size_t alignment = MIN_ALIGNMENT) noexcept;
72+
[[nodiscard]] void *allocate(size_t size, size_t alignment = MIN_ALIGNMENT) noexcept;
7773
void free(void *ptr) noexcept;
7874

7975
private:
8076
void coalescence(Node *prevNode, Node *freeNode) noexcept;
8177
void find(size_t size, size_t alignment, size_t &padding, Node *&previousNode,
82-
Node *&foundNode) noexcept;
78+
Node *&foundNode) const noexcept;
8379
};
8480

8581
} // namespace corosig

include/corosig/Coro.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct CoroutinePromiseType : CoroListNode {
7777

7878
template <std::convertible_to<Result<T, E>> U>
7979
void return_value(U &&value) noexcept {
80+
[[clang::suppress]] // false positives about m_out being uninitialized
8081
assert(m_out);
8182
m_out->m_value.emplace(std::forward<U>(value));
8283
m_waiting_coro.resume();
@@ -91,7 +92,6 @@ struct CoroutinePromiseType : CoroListNode {
9192
} else {
9293
m_out->m_value.emplace(success(std::move(result.assume_value())));
9394
}
94-
9595
} else {
9696
m_out->m_value.emplace(std::move(result.assume_error()));
9797
}
@@ -106,7 +106,7 @@ struct CoroutinePromiseType : CoroListNode {
106106
friend struct Fut<T, E, REACTOR>;
107107

108108
std::coroutine_handle<> m_waiting_coro = std::noop_coroutine();
109-
Fut<T, E, REACTOR> *m_out{nullptr};
109+
Fut<T, E, REACTOR> *m_out = nullptr;
110110
};
111111

112112
} // namespace detail
@@ -131,7 +131,7 @@ struct [[nodiscard("forgot to await?")]] Fut {
131131
return *this;
132132
};
133133

134-
bool has_value() const noexcept {
134+
[[nodiscard]] bool has_value() const noexcept {
135135
return m_value.has_value();
136136
}
137137

@@ -159,7 +159,7 @@ struct [[nodiscard("forgot to await?")]] Fut {
159159
Awaiter &operator=(const Awaiter &) = delete;
160160
Awaiter &operator=(Awaiter &&) = delete;
161161

162-
bool await_ready() const noexcept {
162+
[[nodiscard]] bool await_ready() const noexcept {
163163
return m_future.has_value();
164164
}
165165

include/corosig/ErrorTypes.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#pragma once
22

3-
#include "boost/mp11/algorithm.hpp"
4-
#include "boost/mp11/detail/mp_list.hpp"
5-
#include "boost/mp11/detail/mp_rename.hpp"
63
#include "corosig/util/Overloaded.hpp"
4+
75
#include <boost/mp11.hpp>
6+
#include <boost/mp11/algorithm.hpp>
87
#include <concepts>
98
#include <cstring>
109
#include <type_traits>
@@ -36,36 +35,36 @@ struct Error : std::variant<TYPES...> {
3635
public:
3736
using Base::Base;
3837

39-
char const *description() const noexcept {
38+
[[nodiscard]] char const *description() const noexcept {
4039
return visit(Overloaded{
4140
[](detail::WithDescription auto const &e) { return e.description(); },
4241
[](auto const &e) { return typeid(std::decay_t<decltype(e)>).name(); },
4342
});
4443
}
4544

4645
template <typename T>
47-
bool holds() const noexcept {
46+
[[nodiscard]] bool holds() const noexcept {
4847
return std::holds_alternative<T>(*this);
4948
}
5049

5150
template <typename F>
52-
decltype(auto) visit(F &&f) noexcept {
51+
[[nodiscard]] decltype(auto) visit(F &&f) noexcept {
5352
return std::visit(std::forward<F>(f), *this);
5453
}
5554

5655
template <typename F>
57-
decltype(auto) visit(F &&f) const noexcept {
56+
[[nodiscard]] decltype(auto) visit(F &&f) const noexcept {
5857
return std::visit(std::forward<F>(f), *this);
5958
}
6059
};
6160

6261
namespace detail {
6362

6463
template <template <class...> class, class>
65-
struct is_instance_of : std::false_type {};
64+
struct IsInstanceOf : std::false_type {};
6665

67-
template <template <class...> class TMPL, class... Args>
68-
struct is_instance_of<TMPL, TMPL<Args...>> : std::true_type {};
66+
template <template <class...> class TMPL, class... ARGS>
67+
struct IsInstanceOf<TMPL, TMPL<ARGS...>> : std::true_type {};
6968

7069
template <template <typename...> typename TMPL, typename... TS>
7170
using apply_unique =
@@ -81,8 +80,8 @@ struct extend_error_impl<Error<E1...>, Error<E2...>> {
8180

8281
template <typename E1, typename E2>
8382
using extend_error =
84-
extend_error_impl<std::conditional_t<is_instance_of<Error, E1>::value, E1, Error<E1>>,
85-
std::conditional_t<is_instance_of<Error, E2>::value, E2, Error<E2>>>::type;
83+
extend_error_impl<std::conditional_t<IsInstanceOf<Error, E1>::value, E1, Error<E1>>,
84+
std::conditional_t<IsInstanceOf<Error, E2>::value, E2, Error<E2>>>::type;
8685

8786
} // namespace detail
8887

@@ -99,7 +98,7 @@ struct SyscallError {
9998

10099
static SyscallError current() noexcept;
101100

102-
char const *description() const noexcept;
101+
[[nodiscard]] char const *description() const noexcept;
103102

104103
int value;
105104
};

include/corosig/Parallel.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "corosig/Coro.hpp"
22
#include "corosig/ErrorTypes.hpp"
33
#include "corosig/Result.hpp"
4+
45
#include <boost/mp11/algorithm.hpp>
56
#include <optional>
67

0 commit comments

Comments
 (0)