Skip to content

Commit 47ed070

Browse files
committed
Fix clang-tidy configuration and tidy up code
1 parent 65dff1f commit 47ed070

25 files changed

+306
-494
lines changed

.clang-tidy

+2-196
Original file line numberDiff line numberDiff line change
@@ -10,205 +10,11 @@ Checks: '
1010
cppcoreguidelines-*,
1111
llvm-*,
1212
cert-*,
13-
-clang-analyzer-core.CallAndMessage'
13+
-clang-analyzer-core.CallAndMessage,
14+
-readability-redundant-member-init'
1415
WarningsAsErrors: true
1516
HeaderFilterRegex: ''
16-
AnalyzeTemporaryDtors: false
1717
FormatStyle: none
1818
CheckOptions:
19-
- key: cert-dcl16-c.NewSuffixes
20-
value: 'L;LL;LU;LLU'
21-
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
22-
value: '0'
23-
- key: cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues
24-
value: '1.0;100.0;'
25-
- key: cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues
26-
value: '1;2;3;4;'
27-
- key: cppcoreguidelines-explicit-virtual-functions.FinalSpelling
28-
value: final
29-
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
30-
value: '1'
31-
- key: cppcoreguidelines-explicit-virtual-functions.OverrideSpelling
32-
value: override
33-
- key: cppcoreguidelines-macro-usage.AllowedRegexp
34-
value: '^DEBUG_*'
35-
- key: cppcoreguidelines-macro-usage.CheckCapsOnly
36-
value: '0'
37-
- key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros
38-
value: '1'
39-
- key: cppcoreguidelines-no-malloc.Allocations
40-
value: '::malloc;::calloc'
41-
- key: cppcoreguidelines-no-malloc.Deallocations
42-
value: '::free'
43-
- key: cppcoreguidelines-no-malloc.Reallocations
44-
value: '::realloc'
45-
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
46-
value: '1'
47-
- key: cppcoreguidelines-owning-memory.LegacyResourceConsumers
48-
value: '::free;::realloc;::freopen;::fclose'
49-
- key: cppcoreguidelines-owning-memory.LegacyResourceProducers
50-
value: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile'
51-
- key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader
52-
value: ''
53-
- key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle
54-
value: 'llvm'
55-
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
56-
value: '0'
57-
- key: cppcoreguidelines-pro-type-member-init.UseAssignment
58-
value: '0'
59-
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
60-
value: '0'
61-
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
62-
value: '0'
63-
- key: google-readability-braces-around-statements.ShortStatementLines
64-
value: '1'
65-
- key: google-readability-function-size.StatementThreshold
66-
value: '800'
67-
- key: google-readability-namespace-comments.ShortNamespaceLines
68-
value: '10'
69-
- key: google-readability-namespace-comments.SpacesBeforeComments
70-
value: '2'
71-
- key: llvm-namespace-comment.ShortNamespaceLines
72-
value: '1'
73-
- key: llvm-namespace-comment.SpacesBeforeComments
74-
value: '1'
75-
- key: modernize-loop-convert.MaxCopySize
76-
value: '16'
77-
- key: modernize-loop-convert.MinConfidence
78-
value: reasonable
79-
- key: modernize-loop-convert.NamingStyle
80-
value: CamelCase
81-
- key: modernize-make-shared.IgnoreMacros
82-
value: '1'
83-
- key: modernize-make-shared.IncludeStyle
84-
value: 'llvm'
85-
- key: modernize-make-shared.MakeSmartPtrFunction
86-
value: 'std::make_shared'
87-
- key: modernize-make-shared.MakeSmartPtrFunctionHeader
88-
value: memory
89-
- key: modernize-make-unique.IgnoreMacros
90-
value: '1'
91-
- key: modernize-make-unique.IncludeStyle
92-
value: 'llvm'
93-
- key: modernize-make-unique.MakeSmartPtrFunction
94-
value: 'std::make_unique'
95-
- key: modernize-make-unique.MakeSmartPtrFunctionHeader
96-
value: memory
97-
- key: modernize-pass-by-value.IncludeStyle
98-
value: llvm
99-
- key: modernize-pass-by-value.ValuesOnly
100-
value: '0'
101-
- key: modernize-raw-string-literal.ReplaceShorterLiterals
102-
value: '0'
103-
- key: modernize-replace-auto-ptr.IncludeStyle
104-
value: llvm
105-
- key: modernize-replace-random-shuffle.IncludeStyle
106-
value: llvm
107-
- key: modernize-use-auto.MinTypeNameLength
108-
value: '5'
109-
- key: modernize-use-auto.RemoveStars
110-
value: '0'
111-
- key: modernize-use-default-member-init.IgnoreMacros
112-
value: '1'
113-
- key: modernize-use-default-member-init.UseAssignment
114-
value: '0'
115-
- key: modernize-use-emplace.ContainersWithPushBack
116-
value: '::std::vector;::std::list;::std::deque'
117-
- key: modernize-use-emplace.SmartPointers
118-
value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr'
119-
- key: modernize-use-emplace.TupleMakeFunctions
120-
value: '::std::make_pair;::std::make_tuple'
121-
- key: modernize-use-emplace.TupleTypes
122-
value: '::std::pair;::std::tuple'
123-
- key: modernize-use-equals-default.IgnoreMacros
124-
value: '1'
125-
- key: modernize-use-equals-delete.IgnoreMacros
126-
value: '1'
127-
- key: modernize-use-nodiscard.ReplacementString
128-
value: '[[nodiscard]]'
129-
- key: modernize-use-noexcept.ReplacementString
130-
value: ''
131-
- key: modernize-use-noexcept.UseNoexceptFalse
132-
value: '1'
133-
- key: modernize-use-nullptr.NullMacros
134-
value: 'NULL'
135-
- key: modernize-use-override.FinalSpelling
136-
value: final
137-
- key: modernize-use-override.IgnoreDestructors
138-
value: '0'
139-
- key: modernize-use-override.OverrideSpelling
140-
value: override
141-
- key: modernize-use-transparent-functors.SafeMode
142-
value: '0'
143-
- key: modernize-use-using.IgnoreMacros
144-
value: '1'
145-
- key: performance-faster-string-find.StringLikeClasses
146-
value: 'std::basic_string'
147-
- key: performance-for-range-copy.AllowedTypes
148-
value: ''
149-
- key: performance-for-range-copy.WarnOnAllAutoCopies
150-
value: '0'
151-
- key: performance-inefficient-string-concatenation.StrictMode
152-
value: '0'
153-
- key: performance-inefficient-vector-operation.VectorLikeClasses
154-
value: '::std::vector'
155-
- key: performance-move-const-arg.CheckTriviallyCopyableMove
156-
value: '1'
157-
- key: performance-move-constructor-init.IncludeStyle
158-
value: llvm
159-
- key: performance-type-promotion-in-math-fn.IncludeStyle
160-
value: llvm
161-
- key: performance-unnecessary-copy-initialization.AllowedTypes
162-
value: ''
163-
- key: performance-unnecessary-value-param.AllowedTypes
164-
value: ''
165-
- key: performance-unnecessary-value-param.IncludeStyle
166-
value: llvm
167-
- key: portability-simd-intrinsics.Std
168-
value: ''
169-
- key: portability-simd-intrinsics.Suggest
170-
value: '0'
171-
- key: readability-braces-around-statements.ShortStatementLines
172-
value: '0'
173-
- key: readability-function-size.BranchThreshold
174-
value: '4294967295'
175-
- key: readability-function-size.LineThreshold
176-
value: '4294967295'
177-
- key: readability-function-size.NestingThreshold
178-
value: '4294967295'
179-
- key: readability-function-size.ParameterThreshold
180-
value: '4294967295'
181-
- key: readability-function-size.StatementThreshold
182-
value: '800'
183-
- key: readability-function-size.VariableThreshold
184-
value: '4294967295'
18519
- key: readability-identifier-length.MinimumParameterNameLength
18620
value: 2
187-
- key: readability-identifier-naming.IgnoreFailedSplit
188-
value: '0'
189-
- key: readability-implicit-bool-conversion.AllowIntegerConditions
190-
value: '0'
191-
- key: readability-implicit-bool-conversion.AllowPointerConditions
192-
value: '0'
193-
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
194-
value: '1'
195-
- key: readability-inconsistent-declaration-parameter-name.Strict
196-
value: '0'
197-
- key: readability-magic-numbers.IgnoredFloatingPointValues
198-
value: '1.0;100.0;'
199-
- key: readability-magic-numbers.IgnoredIntegerValues
200-
value: '1;2;3;4;'
201-
- key: readability-redundant-smartptr-get.IgnoreMacros
202-
value: '1'
203-
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
204-
value: '0'
205-
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
206-
value: '0'
207-
- key: readability-simplify-subscript-expr.Types
208-
value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array'
209-
- key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold
210-
value: '3'
211-
- key: readability-uppercase-literal-suffix.IgnoreMacros
212-
value: '1'
213-
- key: readability-uppercase-literal-suffix.NewSuffixes
214-
value: ''

examples/power_train/main.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RightPedal : public Reactor {
4444
Reaction r1{"1", 1, this, [this]() { reaction_1(); }};
4545
Reaction r2{"2", 2, this, [this]() { reaction_2(); }};
4646

47-
void reaction_1(){};
47+
void reaction_1() {};
4848
void reaction_2() {}
4949

5050
public:

include/reactor-cpp/action.hh

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class BaseAction : public ReactorElement {
2828
private:
2929
std::set<Reaction*> triggers_{};
3030
std::set<Reaction*> schedulers_{};
31-
const Duration min_delay_{0};
32-
const bool logical_{true};
31+
Duration min_delay_{0};
32+
bool logical_{true};
3333
bool present_{false};
3434

3535
protected:
@@ -58,12 +58,12 @@ protected:
5858
BaseAction(const std::string& name, Environment* environment, bool logical, Duration min_delay);
5959

6060
public:
61-
[[nodiscard]] auto inline triggers() const noexcept -> const auto& { return triggers_; }
62-
[[nodiscard]] auto inline schedulers() const noexcept -> const auto& { return schedulers_; }
63-
[[nodiscard]] auto inline is_logical() const noexcept -> bool { return logical_; }
64-
[[nodiscard]] auto inline is_physical() const noexcept -> bool { return !logical_; }
65-
[[nodiscard]] auto inline min_delay() const noexcept -> Duration { return min_delay_; }
66-
[[nodiscard]] auto inline is_present() const noexcept -> bool { return present_; }
61+
[[nodiscard]] auto triggers() const noexcept -> const auto& { return triggers_; }
62+
[[nodiscard]] auto schedulers() const noexcept -> const auto& { return schedulers_; }
63+
[[nodiscard]] auto is_logical() const noexcept -> bool { return logical_; }
64+
[[nodiscard]] auto is_physical() const noexcept -> bool { return !logical_; }
65+
[[nodiscard]] auto min_delay() const noexcept -> Duration { return min_delay_; }
66+
[[nodiscard]] auto is_present() const noexcept -> bool { return present_; }
6767

6868
friend class Reaction;
6969
friend class Scheduler;
@@ -108,15 +108,15 @@ public:
108108
auto schedule_at(const ImmutableValuePtr<T>& value_ptr, const Tag& tag) -> bool;
109109

110110
template <class Dur = Duration> void schedule(MutableValuePtr<T>&& value_ptr, Dur delay = Dur::zero()) {
111-
schedule(ImmutableValuePtr<T>(std::forward<MutableValuePtr<T>>(value_ptr)), delay);
111+
schedule(ImmutableValuePtr<T>(std::move(value_ptr)), delay);
112112
}
113113

114114
template <class Dur = Duration> void schedule(const T& value, Dur delay = Dur::zero()) {
115115
schedule(make_immutable_value<T>(value), delay);
116116
}
117117

118118
template <class Dur = Duration> void schedule(T&& value, Dur delay = Dur::zero()) {
119-
schedule(make_immutable_value<T>(std::forward<T>(value)), delay);
119+
schedule(make_immutable_value<T>(std::move(value)), delay);
120120
}
121121

122122
// Scheduling an action with nullptr value is not permitted.
@@ -153,8 +153,8 @@ public:
153153

154154
class Timer : public BaseAction {
155155
private:
156-
const Duration offset_{0};
157-
const Duration period_{0};
156+
Duration offset_{0};
157+
Duration period_{0};
158158

159159
void cleanup() noexcept final;
160160

include/reactor-cpp/assert.hh

+7-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ constexpr bool runtime_assertion = true;
3434

3535
#ifdef REACTOR_CPP_USE_BACKTRACE
3636

37-
// NOLINTNEXTLINE
37+
// NOLINTNEXTLINE(llvm-include-order)
3838
#include REACTOR_CPP_BACKTRACE_HEADER
3939
#include <array>
4040
#include <iostream>
@@ -48,7 +48,8 @@ inline void print_backtrace() {
4848
int size = backtrace(trace.data(), MAX_TRACE_SIZE);
4949
char** messages = backtrace_symbols(trace.data(), size);
5050
for (int i{0}; i < size; i++) {
51-
std::cerr << "[backtrace] " << messages[i] << '\n'; // NOLINT
51+
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
52+
std::cerr << "[backtrace] " << messages[i] << '\n';
5253
}
5354
}
5455

@@ -70,17 +71,17 @@ public:
7071
: std::runtime_error(build_message(msg)) {}
7172
};
7273

73-
constexpr inline void validate([[maybe_unused]] bool condition, [[maybe_unused]] const std::string_view message) {
74-
if constexpr (runtime_validation) { // NOLINT
74+
constexpr void validate([[maybe_unused]] bool condition, [[maybe_unused]] const std::string_view message) {
75+
if constexpr (runtime_validation) {
7576
if (!condition) {
7677
print_backtrace();
7778
throw ValidationError(message);
7879
}
7980
}
8081
}
8182

82-
template <typename E> constexpr auto extract_value(E enum_value) -> typename std::underlying_type<E>::type {
83-
return static_cast<typename std::underlying_type<E>::type>(enum_value);
83+
template <typename E> constexpr auto extract_value(E enum_value) -> typename std::underlying_type_t<E> {
84+
return static_cast<typename std::underlying_type_t<E>>(enum_value);
8485
}
8586

8687
void assert_phase([[maybe_unused]] const ReactorElement* ptr, [[maybe_unused]] Phase phase);

0 commit comments

Comments
 (0)