Skip to content

Commit 58bda56

Browse files
committed
clang-tidy fixes
Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
1 parent 60673d3 commit 58bda56

13 files changed

Lines changed: 41 additions & 33 deletions

File tree

.clang-tidy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ Checks: >
1818
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
1919
clang-analyzer-*,
2020
hicpp-*,
21+
-hicpp-explicit-conversions,
22+
-hicpp-signed-bitwise,
2123
portability-*,
2224
misc-*,
25+
-misc-include-cleaner,
26+
-misc-non-private-member-variables-in-classes,
27+
-misc-unconventional-assign-operator
2328
2429
WarningsAsErrors: '*'
2530
HeaderFilterRegex: '.*'
26-
ExcludePaths: '.*\\.test\\.cpp$'
2731
FormatStyle: file
2832
CheckOptions:
2933
- key: readability-braces-around-statements.ShortStatementLines

.github/workflows/codeql.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [ "main" ]
66
pull_request:
77
branches: [ "main" ]
8-
schedule:
9-
- cron: '25 3 * * 2'
108

119
jobs:
1210
analyze:

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
DST=$(git tag)
2323
fi
2424
mkdir -p web/dist/$DST
25-
quom -g __BITFILLED_.* -I bitfilled bitfilled/bitfilled.hpp web/dist/$DST/bitfilled.hpp
25+
quom -I bitfilled bitfilled/bitfilled.hpp web/dist/$DST/bitfilled.hpp
2626
2727
- name: Deploy
2828
uses: JamesIves/github-pages-deploy-action@v4

bitfilled/bitfield_traits.hpp

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

54
#include <array>
65
#include "bitfilled/size.hpp"
@@ -62,15 +61,16 @@ constexpr inline std::endian endianness = []() constexpr
6261
return x == 1 ? std::endian::little : std::endian::big;
6362
}();
6463
#else
65-
inline std::endian endianness = []()
64+
const inline std::endian endianness = []()
6665
{
6766
struct s
6867
{
69-
char a : 1 = 1;
68+
bool a : 1 = true;
7069
char b : 7 = 0;
71-
} val;
72-
static const auto x = std::bit_cast<std::array<char, bitfilled::aligned_size<s>>>(val).front();
73-
return x == 1 ? std::endian::little : std::endian::big;
70+
} const val;
71+
static const auto ended =
72+
std::bit_cast<std::array<char, bitfilled::aligned_size<s>>>(val).front();
73+
return ended == 1 ? std::endian::little : std::endian::big;
7474
}();
7575
#endif
7676

@@ -80,10 +80,8 @@ constexpr inline bool overflow_wraps = []() constexpr
8080
struct s
8181
{
8282
int a : 2;
83-
} val{2};
83+
} const val{2}; // NOLINT(clang-diagnostic-bitfield-constant-conversion)
8484
return val.a == -2;
8585
}();
8686

8787
} // namespace bitfield_traits
88-
89-
#endif // __BITFIELD_TRAITS_HPP__

bitfilled/bitfilled/base_ops.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct bitfield_props
5858
template <typename T = unsigned>
5959
constexpr static T mask()
6060
{
61-
return ((1 << size_bits()) - 1);
61+
return ((1U << size_bits()) - 1U);
6262
}
6363
template <typename T>
6464
constexpr static T extract_field(T memory)
@@ -83,7 +83,7 @@ struct bitfield_props
8383
struct
8484
{
8585
T field : size_bits();
86-
} storage{.field = v};
86+
} const storage{.field = v};
8787
return storage.field;
8888
}
8989
return v;
@@ -108,7 +108,7 @@ struct regbitfieldset_props : public bitfield_props<OFFSET, ITEM_SIZE + OFFSET -
108108

109109
constexpr static std::size_t offset(std::size_t index)
110110
{
111-
return base::offset() + index * base::size_bits();
111+
return base::offset() + (index * base::size_bits());
112112
}
113113
template <typename T>
114114
constexpr static T extract_field(T memory, std::size_t index)

bitfilled/bitfilled/bits.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ struct regbitfieldset
212212
operator=(const regbitfieldset & other)
213213
requires(is_readwrite<ACCESS>)
214214
{
215-
using bf_type = regbitfield<T, TOps, ACCESS, OFFSET, OFFSET + ITEM_COUNT * ITEM_SIZE - 1>;
215+
using bf_type = regbitfield<T, TOps, ACCESS, OFFSET, OFFSET + (ITEM_COUNT * ITEM_SIZE) - 1>;
216216
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
217217
reinterpret_cast<bf_type&>(*this) = reinterpret_cast<const bf_type&>(other);
218218
return BITFILLED_ASSIGN_RETURN_EXPR(reinterpret_cast<bf_type&>(*this));
@@ -222,7 +222,7 @@ struct regbitfieldset
222222
operator=(const regbitfieldset& other) volatile
223223
requires(is_readwrite<ACCESS>)
224224
{
225-
using bf_type = regbitfield<T, TOps, ACCESS, OFFSET, OFFSET + ITEM_COUNT * ITEM_SIZE - 1>;
225+
using bf_type = regbitfield<T, TOps, ACCESS, OFFSET, OFFSET + (ITEM_COUNT * ITEM_SIZE) - 1>;
226226
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
227227
reinterpret_cast<volatile bf_type&>(*this) = reinterpret_cast<const bf_type&>(other);
228228
return BITFILLED_ASSIGN_RETURN_EXPR(reinterpret_cast<volatile bf_type&>(*this));

bitfilled/bitfilled/integer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
7070
// if the value is signed, fill the target with sign extend bytes
7171
if (std::is_signed_v<T> and (value < static_cast<T>(0)))
7272
{
73-
std::fill(this->begin(), this->end(), 0xffu);
73+
std::fill(this->begin(), this->end(), 0xffU);
7474
}
7575

7676
// byteswap if the endian is not native
@@ -120,9 +120,9 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
120120

121121
// if the value is signed, fill the target with sign extend bytes
122122
if (std::is_signed_v<T> and
123-
((endianness == std::endian::little ? this->back() : this->front()) & 0x80u))
123+
((endianness == std::endian::little ? this->back() : this->front()) & 0x80U))
124124
{
125-
std::fill(value_repr.begin(), value_repr.end(), 0xffu);
125+
std::fill(value_repr.begin(), value_repr.end(), 0xffU);
126126
}
127127

128128
// transfer the bytes to the correct position
@@ -176,7 +176,7 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
176176
template <std::endian ENDIAN, std::size_t SIZE, Integral T = sized_unsigned_t<std::bit_ceil(SIZE)>>
177177
struct packed_integer
178178
{
179-
protected:
179+
protected: // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
180180
integer_storage<SIZE> storage;
181181

182182
public:

test/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ include(get_cpm)
22
CPMAddPackage("gh:boost-ext/ut@2.3.1")
33
include(CTest)
44

5-
add_executable(${PROJECT_NAME}-test main.cpp)
5+
add_library(${PROJECT_NAME}-build-test OBJECT main.cpp)
6+
add_executable(${PROJECT_NAME}-test)
67
target_sources(${PROJECT_NAME}-test
78
PRIVATE
89
integer.test.cpp
910
size.test.cpp
1011
variable_bits.test.cpp
1112
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:mmreg.test.cpp>
1213
)
14+
target_link_libraries(${PROJECT_NAME}-build-test
15+
PUBLIC
16+
${PROJECT_NAME}
17+
)
1318
target_link_libraries(${PROJECT_NAME}-test
1419
PRIVATE
15-
${PROJECT_NAME}
20+
${PROJECT_NAME}-build-test
1621
ut
1722
)
1823
add_test(NAME ${PROJECT_NAME}-test COMMAND ${PROJECT_NAME}-test)
@@ -78,8 +83,8 @@ target_compile_options(${PROJECT_NAME}-test
7883
)
7984

8085
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
81-
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
82-
set_target_properties(${PROJECT_NAME}-test
86+
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" "clang-tidy-20")
87+
set_target_properties(${PROJECT_NAME}-build-test
8388
PROPERTIES
8489
CXX_CLANG_TIDY "${CLANG_TIDY_EXE}"
8590
)

test/integer.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct packed_integer_with_bfs : packed_integer<ENDIAN, SIZE, T>
2525
BF_BITS(unsigned, 0, 15) halfword;
2626
};
2727

28-
const suite integer = []
28+
const suite<"integer"> integer = []
2929
{
3030
"integer_storage"_test = []<class TestType>
3131
{

test/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
#include "bitfield_traits.hpp"
2+
#include "bitfilled.hpp"
3+
14
int main() {}

0 commit comments

Comments
 (0)