Skip to content

Commit dd9697a

Browse files
committed
fix clang-tidy warnings
1 parent d28b93f commit dd9697a

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Checks: >
1212
-google-readability-todo,
1313
-google-readability-namespace-comments,
1414
-google-runtime-references,
15+
-misc-include-cleaner,
1516
-misc-non-private-member-variables-in-classes,
1617
-misc-unused-parameters,
1718
-misc-no-recursion,
@@ -21,6 +22,7 @@ Checks: >
2122
-modernize-avoid-c-arrays,
2223
-modernize-use-auto,
2324
-modernize-use-nodiscard,
25+
-performance-enum-size,
2426
-performance-move-const-arg,
2527
-readability-braces-around-statements,
2628
-readability-identifier-length,

.cppcheck-suppress

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ unusedFunction
44
useStlAlgorithm
55
noExplicitConstructor
66
unusedStructMember
7+
normalCheckLevelMaxBranches
78
*:*_deps/*

cmake/clang_format.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ add_custom_target(
2121
clang-tidy
2222
COMMAND ${PROJECT_SOURCE_DIR}/tools/run-clang-tidy.py
2323
-p . -use-color -header-filter='.*' -quiet
24-
-extra-arg=-std=c++17
24+
-extra-arg=-std=c++17 -extra-arg=-Wno-unknown-warning-option
2525
-ignore ${PROJECT_SOURCE_DIR}/.clang-tidy-ignore
2626
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
2727
USES_TERMINAL

examples/ulog_writer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
using namespace std::chrono_literals;
1212

13-
static uint64_t currentTimeUs()
13+
namespace {
14+
uint64_t currentTimeUs()
1415
{
1516
return std::chrono::duration_cast<std::chrono::microseconds>(
1617
std::chrono::steady_clock::now().time_since_epoch())
1718
.count();
1819
}
20+
} // namespace
1921

2022
struct MyData {
2123
uint64_t timestamp;

test/ulog_parsing_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ TEST_CASE("ULog parsing - basic test: write then read")
108108
}
109109
}
110110

111-
static void readFileWriteTest(const std::filesystem::path& path,
112-
const std::function<unsigned()>& next_chunk_size)
111+
namespace {
112+
void readFileWriteTest(const std::filesystem::path& path,
113+
const std::function<unsigned()>& next_chunk_size)
113114
{
114115
FILE* file = fopen(path.c_str(), "rb");
115116
CHECK(file);
@@ -144,6 +145,7 @@ static void readFileWriteTest(const std::filesystem::path& path,
144145
CHECK_EQ(input_data.size(), written_data.size());
145146
CHECK_EQ(input_data, written_data);
146147
}
148+
} // namespace
147149

148150
TEST_CASE("ULog parsing - read sample files then write")
149151
{
@@ -343,7 +345,7 @@ TEST_CASE("ULog parsing - simple writer")
343345
std::vector<MyData> written_data_messages;
344346
for (int i = 0; i < 100; ++i) {
345347
MyData data{};
346-
data.timestamp = i * 1000;
348+
data.timestamp = static_cast<uint64_t>(i) * 1000;
347349
data.cpuload = cpuload;
348350
data.counter = i;
349351
writer.writeData(my_data_msg_id, data);

ulog_cpp/messages.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Value::NativeTypeVariant Value::asNativeTypeVariant() const
196196
if (_field_ref.arrayLength() == -1 || _array_index >= 0) {
197197
// decode as a single value. Either it is a single value,
198198
// or the user has explicitly selected an array element
199-
int array_offset = _array_index >= 0 ? _array_index : 0;
199+
const int array_offset = _array_index >= 0 ? _array_index : 0;
200200
switch (_field_ref.type().type) {
201201
case Field::BasicType::INT8:
202202
return deserialize<int8_t>(_backing_ref_begin, _backing_ref_end,
@@ -298,8 +298,8 @@ Value Value::operator[](const Field& field) const
298298
if (!_field_ref.definitionResolved()) {
299299
throw AccessException("Cannot access field of unresolved type");
300300
}
301-
int submessage_offset = _field_ref.offsetInMessage() +
302-
((_array_index >= 0) ? _field_ref.type().size * _array_index : 0);
301+
const int submessage_offset = _field_ref.offsetInMessage() +
302+
((_array_index >= 0) ? _field_ref.type().size * _array_index : 0);
303303

304304
return Value(field, _backing_ref_begin + submessage_offset, _backing_ref_end);
305305
}

ulog_cpp/messages.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,25 @@ class Field {
172172
* @brief Get the type attributes of the field
173173
* @return The type attributes
174174
*/
175-
inline const TypeAttributes& type() const { return _type; }
175+
const TypeAttributes& type() const { return _type; }
176176

177177
/**
178178
* @brief Get the array length of the field
179179
* @return The array length, -1 if not an array
180180
*/
181-
inline int arrayLength() const { return _array_length; }
181+
int arrayLength() const { return _array_length; }
182182

183183
/**
184184
* @brief Get the offset of the field in the message. This is only valid if the field is resolved.
185185
* @return The offset in bytes, -1 if not resolved
186186
*/
187-
inline int offsetInMessage() const { return _offset_in_message_bytes; }
187+
int offsetInMessage() const { return _offset_in_message_bytes; }
188188

189189
/**
190190
* @brief Get the name of the field
191191
* @return The name
192192
*/
193-
inline const std::string& name() const { return _name; }
193+
const std::string& name() const { return _name; }
194194

195195
/**
196196
* @brief Get the size of the field in bytes. This is only valid if the field is resolved.
@@ -203,11 +203,11 @@ class Field {
203203
* is defined and the type is not nested or the nested message is resolved.
204204
* @return True if the field is resolved
205205
*/
206-
inline bool definitionResolved() const
206+
bool definitionResolved() const
207207
{
208208
return _offset_in_message_bytes >= 0 &&
209209
(_type.type != BasicType::NESTED || _type.nested_message != nullptr);
210-
};
210+
}
211211

212212
/**
213213
* @brief Attempt to resolve the definition of the field.
@@ -353,8 +353,8 @@ class Value {
353353
// this is natively a vector
354354
if constexpr (is_vector<ReturnType>::value) {
355355
// return type is also vector
356-
if constexpr (std::is_same<typename NativeType::value_type,
357-
typename ReturnType::value_type>::value) {
356+
if constexpr (std::is_same_v<typename NativeType::value_type,
357+
typename ReturnType::value_type>) {
358358
// return type is same as native type
359359
res = arg;
360360
} else {
@@ -428,7 +428,7 @@ class Value {
428428
int array_offset)
429429
{
430430
T v;
431-
int total_offset = offset + array_offset * sizeof(T);
431+
const int total_offset = offset + (array_offset * sizeof(T));
432432
if (backing_start > backing_end ||
433433
backing_end - backing_start < static_cast<int64_t>(sizeof(v)) + total_offset) {
434434
throw AccessException("Unexpected data type size");
@@ -603,6 +603,7 @@ class MessageFormat {
603603
std::vector<std::string> fieldNames() const
604604
{
605605
std::vector<std::string> names;
606+
names.reserve(_fields_ordered.size());
606607
for (const auto& field_it : _fields_ordered) {
607608
names.push_back(field_it->name());
608609
}

ulog_cpp/reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "raw_messages.hpp"
1111

12-
#if 0
12+
#if 0 // NOLINT (readability-avoid-unconditional-preprocessor-if)
1313
#define DBG_PRINTF(...) printf(__VA_ARGS__)
1414
#else
1515
#define DBG_PRINTF(...)

0 commit comments

Comments
 (0)