Skip to content

Commit 8ffe6b6

Browse files
committed
add clang-tidy
1 parent e108749 commit 8ffe6b6

File tree

13 files changed

+185
-129
lines changed

13 files changed

+185
-129
lines changed

.clang-tidy

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Checks: >
2+
modernize-*,
3+
-modernize-use-trailing-return-type,
4+
bugprone-*,
5+
-bugprone-easily-swappable-parameters,
6+
performance-*,
7+
readability*,
8+
-readability-magic-numbers,
9+
-readability-avoid-unconditional-preprocessor-if,
10+
-readability-redundant-control-flow,
11+
-readability-uppercase-literal-suffix,
12+
cppcoreguidelines*,
13+
-cppcoreguidelines-avoid-const-or-ref-data-members,
14+
-cppcoreguidelines-avoid-magic-numbers,
15+
-cppcoreguidelines-c-copy-assignment-signature,
16+
-cppcoreguidelines-macro-usage,
17+
-cppcoreguidelines-pro-bounds-constant-array-index,
18+
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
19+
clang-analyzer-*,
20+
hicpp-*,
21+
portability-*,
22+
misc-*,
23+
24+
WarningsAsErrors: '*'
25+
HeaderFilterRegex: '.*'
26+
ExcludePaths: '.*\\.test\\.cpp$'
27+
FormatStyle: file
28+
CheckOptions:
29+
- key: readability-braces-around-statements.ShortStatementLines
30+
value: '0'
31+
- key: readability-identifier-length.MinimumVariableNameLength
32+
value: '2'
33+
- key: readability-identifier-length.MinimumParameterNameLength
34+
value: '1'
35+
- key: readability-simplify-boolean-expr.IgnoreMacros
36+
value: true

bitfilled/bitfilled/access.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MPL-2.0
2-
#ifndef __BITFILLED_ACCESS_HPP__
3-
#define __BITFILLED_ACCESS_HPP__
2+
#pragma once
43

54
#include <cstdint>
65
#include <type_traits>
@@ -21,12 +20,12 @@ enum class access : std::uint_fast8_t
2120
read_ephemeralwrite = 7, // writes don't get stored when read
2221
};
2322

24-
inline constexpr enum access operator&(enum access lhs, enum access rhs)
23+
constexpr enum access operator&(enum access lhs, enum access rhs)
2524
{
2625
return static_cast<enum access>(static_cast<std::uint_fast8_t>(lhs) &
2726
static_cast<std::uint_fast8_t>(rhs));
2827
}
29-
inline constexpr enum access operator|(enum access lhs, enum access rhs)
28+
constexpr enum access operator|(enum access lhs, enum access rhs)
3029
{
3130
return static_cast<enum access>(static_cast<std::uint_fast8_t>(lhs) |
3231
static_cast<std::uint_fast8_t>(rhs));
@@ -50,5 +49,3 @@ inline constexpr bool is_ephemeralwrite =
5049
(ACCESS & access::read_ephemeralwrite) == access::read_ephemeralwrite;
5150

5251
} // namespace bitfilled
53-
54-
#endif // __BITFILLED_ACCESS_HPP__

bitfilled/bitfilled/base_ops.hpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MPL-2.0
2-
#ifndef __BITFILLED_BASE_OPS_HPP__
3-
#define __BITFILLED_BASE_OPS_HPP__
2+
#pragma once
43

54
#include "bitfilled/access.hpp"
65
#include "bitfilled/macros.hpp"
@@ -33,12 +32,12 @@ struct copy_cv_reference
3332
{
3433
private:
3534
using R = std::remove_reference_t<T>;
36-
using U1 = std::conditional_t<std::is_const<R>::value, std::add_const_t<U>, U>;
37-
using U2 = std::conditional_t<std::is_volatile<R>::value, std::add_volatile_t<U1>, U1>;
35+
using U1 = std::conditional_t<std::is_const_v<R>, std::add_const_t<U>, U>;
36+
using U2 = std::conditional_t<std::is_volatile_v<R>, std::add_volatile_t<U1>, U1>;
3837
using U3 =
39-
std::conditional_t<std::is_lvalue_reference<T>::value, std::add_lvalue_reference_t<U2>, U2>;
38+
std::conditional_t<std::is_lvalue_reference_v<T>, std::add_lvalue_reference_t<U2>, U2>;
4039
using U4 =
41-
std::conditional_t<std::is_rvalue_reference<T>::value, std::add_rvalue_reference_t<U3>, U3>;
40+
std::conditional_t<std::is_rvalue_reference_v<T>, std::add_rvalue_reference_t<U3>, U3>;
4241

4342
public:
4443
using type = U4;
@@ -84,8 +83,8 @@ struct bitfield_props
8483
struct
8584
{
8685
T field : size_bits();
87-
} s{.field = v};
88-
return s.field;
86+
} storage{.field = v};
87+
return storage.field;
8988
}
9089
return v;
9190
}
@@ -150,6 +149,7 @@ struct base
150149
template <typename Tptr>
151150
static void setter(Tptr& ptr, int_type v)
152151
{
152+
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
153153
if constexpr (std::is_void_v<decltype((copy_cv_t<Tptr&, T>)ptr = v)>)
154154
{
155155
(copy_cv_t<Tptr&, T>)ptr = v;
@@ -159,6 +159,7 @@ struct base
159159
// the assignment might return a volatile-qualified reference
160160
// avoid reading it by keeping it a reference, and casting away the qualifier
161161
// all this is to avoid warnings
162+
// NOLINTNEXTLINE(readability-identifier-length)
162163
[[maybe_unused]] auto& _ = const_cast<T&>((copy_cv_t<Tptr&, T>)ptr = v);
163164
}
164165
}
@@ -168,107 +169,105 @@ struct base
168169
static void set_field(BITFILLED_FIELD_PROPS_PARAM_T& bf, TVal value)
169170
requires(is_writeable<bitfield_ops::access()>)
170171
{
171-
const auto v = static_cast<int_type>(value);
172+
const auto intval = static_cast<int_type>(value);
172173
if constexpr (!is_readable<bitfield_ops::access()> or
173174
is_ephemeralwrite<bitfield_ops::access()>)
174175
{
175-
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::position_field(v));
176+
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::position_field(intval));
176177
}
177178
else
178179
{
179-
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::insert_field(getter(bf), v));
180+
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::insert_field(getter(bf), intval));
180181
}
181182
}
182183
template <std::size_t FIRST_BIT, std::size_t LAST_BIT, typename TVal>
183184
static void set_field(volatile BITFILLED_FIELD_PROPS_PARAM_T& bf, TVal value)
184185
requires(is_writeable<bitfield_ops::access()>)
185186
{
186-
const auto v = static_cast<int_type>(value);
187+
const auto intval = static_cast<int_type>(value);
187188
if constexpr (!is_readable<bitfield_ops::access()> or
188189
is_ephemeralwrite<bitfield_ops::access()>)
189190
{
190-
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::position_field(v));
191+
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::position_field(intval));
191192
}
192193
else
193194
{
194-
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::insert_field(getter(bf), v));
195+
setter(bf, bitfield_props<FIRST_BIT, LAST_BIT>::insert_field(getter(bf), intval));
195196
}
196197
}
197198

198199
template <typename TVal, std::size_t FIRST_BIT, std::size_t LAST_BIT>
199200
static TVal get_field(const BITFILLED_FIELD_PROPS_PARAM_T& bf)
200201
requires(is_readable<bitfield_ops::access()>)
201202
{
202-
auto x =
203+
auto typeval =
203204
static_cast<TVal>(bitfield_props<FIRST_BIT, LAST_BIT>::extract_field(getter(bf)));
204-
return bitfield_props<FIRST_BIT, LAST_BIT>::sign_extend(x);
205+
return bitfield_props<FIRST_BIT, LAST_BIT>::sign_extend(typeval);
205206
}
206207
template <typename TVal, std::size_t FIRST_BIT, std::size_t LAST_BIT>
207208
static TVal get_field(const volatile BITFILLED_FIELD_PROPS_PARAM_T& bf)
208209
requires(is_readable<bitfield_ops::access()>)
209210
{
210-
auto x =
211+
auto typeval =
211212
static_cast<TVal>(bitfield_props<FIRST_BIT, LAST_BIT>::extract_field(getter(bf)));
212-
return bitfield_props<FIRST_BIT, LAST_BIT>::sign_extend(x);
213+
return bitfield_props<FIRST_BIT, LAST_BIT>::sign_extend(typeval);
213214
}
214215

215216
template <std::size_t ITEM_SIZE, std::size_t ITEM_COUNT, std::size_t OFFSET, typename TVal>
216217
static void set_item(BITFILLED_FIELDSET_PROPS_PARAM_T& bf, std::size_t index, TVal value)
217218
requires(is_writeable<bitfield_ops::access()>)
218219
{
219-
const auto v = static_cast<int_type>(value);
220+
const auto intval = static_cast<int_type>(value);
220221
if constexpr (!is_readable<bitfield_ops::access()> or
221222
is_ephemeralwrite<bitfield_ops::access()>)
222223
{
223224
setter(bf, regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::position_field(
224-
v, index));
225+
intval, index));
225226
}
226227
else
227228
{
228229
setter(bf, regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::insert_field(
229-
getter(bf), v, index));
230+
getter(bf), intval, index));
230231
}
231232
}
232233
template <std::size_t ITEM_SIZE, std::size_t ITEM_COUNT, std::size_t OFFSET, typename TVal>
233234
static void set_item(volatile BITFILLED_FIELDSET_PROPS_PARAM_T& bf, std::size_t index,
234235
TVal value)
235236
requires(is_writeable<bitfield_ops::access()>)
236237
{
237-
const auto v = static_cast<int_type>(value);
238+
const auto intval = static_cast<int_type>(value);
238239
if constexpr (!is_readable<bitfield_ops::access()> or
239240
is_ephemeralwrite<bitfield_ops::access()>)
240241
{
241242
setter(bf, regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::position_field(
242-
v, index));
243+
intval, index));
243244
}
244245
else
245246
{
246247
setter(bf, regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::insert_field(
247-
getter(bf), v, index));
248+
getter(bf), intval, index));
248249
}
249250
}
250251

251252
template <typename TVal, std::size_t ITEM_SIZE, std::size_t ITEM_COUNT, std::size_t OFFSET>
252253
static TVal get_item(const BITFILLED_FIELDSET_PROPS_PARAM_T& bf, std::size_t index)
253254
requires(is_readable<bitfield_ops::access()>)
254255
{
255-
auto x = static_cast<TVal>(
256+
auto typeval = static_cast<TVal>(
256257
regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::extract_field(getter(bf),
257258
index));
258-
return regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::sign_extend(x);
259+
return regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::sign_extend(typeval);
259260
}
260261
template <typename TVal, std::size_t ITEM_SIZE, std::size_t ITEM_COUNT, std::size_t OFFSET>
261262
static TVal get_item(const volatile BITFILLED_FIELDSET_PROPS_PARAM_T& bf, std::size_t index)
262263
requires(is_readable<bitfield_ops::access()>)
263264
{
264-
auto x = static_cast<TVal>(
265+
auto typeval = static_cast<TVal>(
265266
regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::extract_field(getter(bf),
266267
index));
267-
return regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::sign_extend(x);
268+
return regbitfieldset_props<ITEM_SIZE, ITEM_COUNT, OFFSET>::sign_extend(typeval);
268269
}
269270
};
270271
};
271272

272273
} // namespace bitfilled
273-
274-
#endif // __BITFILLED_BASE_OPS_HPP__

bitfilled/bitfilled/bitband_ops.hpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MPL-2.0
2-
#ifndef __BITFILLED_BITBAND_OPS_HPP__
3-
#define __BITFILLED_BITBAND_OPS_HPP__
2+
#pragma once
43

54
#include "bitfilled/base_ops.hpp"
65

@@ -42,8 +41,8 @@ struct bitband
4241
{
4342
if constexpr (FIRST_BIT == LAST_BIT)
4443
{
45-
const auto v = static_cast<base_ops::int_type>(value);
46-
bitmemory(bf, FIRST_BIT) = v;
44+
const auto intval = static_cast<base_ops::int_type>(value);
45+
bitmemory(bf, FIRST_BIT) = intval;
4746
}
4847
else
4948
{
@@ -56,8 +55,8 @@ struct bitband
5655
{
5756
if constexpr (FIRST_BIT == LAST_BIT)
5857
{
59-
const auto v = static_cast<base_ops::int_type>(value);
60-
bitmemory(bf, FIRST_BIT) = v;
58+
const auto intval = static_cast<base_ops::int_type>(value);
59+
bitmemory(bf, FIRST_BIT) = intval;
6160
}
6261
else
6362
{
@@ -70,8 +69,8 @@ struct bitband
7069
{
7170
if constexpr (FIRST_BIT == LAST_BIT)
7271
{
73-
auto x = static_cast<TVal>(bitmemory(bf, FIRST_BIT));
74-
return bf.sign_extend(x);
72+
auto typeval = static_cast<TVal>(bitmemory(bf, FIRST_BIT));
73+
return bf.sign_extend(typeval);
7574
}
7675
else
7776
{
@@ -84,8 +83,8 @@ struct bitband
8483
{
8584
if constexpr (FIRST_BIT == LAST_BIT)
8685
{
87-
auto x = static_cast<TVal>(bitmemory(bf, FIRST_BIT));
88-
return bf.sign_extend(x);
86+
auto typeval = static_cast<TVal>(bitmemory(bf, FIRST_BIT));
87+
return bf.sign_extend(typeval);
8988
}
9089
else
9190
{
@@ -99,8 +98,8 @@ struct bitband
9998
{
10099
if constexpr (ITEM_SIZE == 1)
101100
{
102-
const auto v = static_cast<base_ops::int_type>(value);
103-
bitmemory(bf, OFFSET + index) = v;
101+
const auto intval = static_cast<base_ops::int_type>(value);
102+
bitmemory(bf, OFFSET + index) = intval;
104103
}
105104
else
106105
{
@@ -114,8 +113,8 @@ struct bitband
114113
{
115114
if constexpr (ITEM_SIZE == 1)
116115
{
117-
const auto v = static_cast<base_ops::int_type>(value);
118-
bitmemory(bf, OFFSET + index) = v;
116+
const auto intval = static_cast<base_ops::int_type>(value);
117+
bitmemory(bf, OFFSET + index) = intval;
119118
}
120119
else
121120
{
@@ -129,8 +128,8 @@ struct bitband
129128
{
130129
if constexpr (ITEM_SIZE == 1)
131130
{
132-
auto x = static_cast<TVal>(bitmemory(bf, OFFSET + index));
133-
return bf.sign_extend(x);
131+
auto typeval = static_cast<TVal>(bitmemory(bf, OFFSET + index));
132+
return bf.sign_extend(typeval);
134133
}
135134
else
136135
{
@@ -144,8 +143,8 @@ struct bitband
144143
{
145144
if constexpr (ITEM_SIZE == 1)
146145
{
147-
auto x = static_cast<TVal>(bitmemory(bf, OFFSET + index));
148-
return bf.sign_extend(x);
146+
auto typeval = static_cast<TVal>(bitmemory(bf, OFFSET + index));
147+
return bf.sign_extend(typeval);
149148
}
150149
else
151150
{
@@ -156,5 +155,3 @@ struct bitband
156155
};
157156

158157
} // namespace bitfilled
159-
160-
#endif // __BITFILLED_BITBAND_OPS_HPP__

0 commit comments

Comments
 (0)