Skip to content

Commit 3b5af4c

Browse files
committed
Add static checker config + small fixes (clang-tidy, clazy)
1 parent 2733ea6 commit 3b5af4c

22 files changed

+71
-16
lines changed

.clang-tidy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
Checks: |
3+
modernize-*,
4+
-modernize-use-trailing-return-type,
5+
-modernize-avoid-c-arrays,
6+
isc-*,
7+
performance-*,
8+
readability-*,
9+
-readability-braces-around-statements,
10+
-readability-implicit-bool-conversion,
11+
-readability-magic-numbers,
12+
-readability-isolate-declaration,
13+
-readability-function-cognitive-complexity,
14+
bugprone-*,
15+
concurrency-*
16+
portability-*
17+
...

include/lsl_cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ class stream_outlet {
790790

791791
/// Check whether a given data length matches the number of channels; throw if not
792792
void check_numchan(std::size_t N) const {
793-
if (N != channel_count)
793+
if (N != static_cast<std::size_t>(channel_count))
794794
throw std::runtime_error("Provided element count (" + std::to_string(N) +
795795
") does not match the stream's channel count (" +
796796
std::to_string(channel_count) + '.');

src/inlet_connection.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,23 @@ ip::address resolve_v6_addr(const std::string &addr) {
127127
tcp::endpoint inlet_connection::get_tcp_endpoint() {
128128
shared_lock_t lock(host_info_mut_);
129129
if (tcp_protocol_ == tcp::v4())
130-
return tcp::endpoint(ip::make_address(host_info_.v4address()), host_info_.v4data_port());
130+
return {ip::make_address(host_info_.v4address()), host_info_.v4data_port()};
131131

132132
std::string addr = host_info_.v6address();
133133
uint16_t port = host_info_.v6data_port();
134134
lock.unlock();
135-
return tcp::endpoint(resolve_v6_addr(addr), port);
135+
return {resolve_v6_addr(addr), port};
136136
}
137137

138138
udp::endpoint inlet_connection::get_udp_endpoint() {
139139
shared_lock_t lock(host_info_mut_);
140-
141140
if (udp_protocol_ == udp::v4())
142-
return udp::endpoint(ip::make_address(host_info_.v4address()), host_info_.v4service_port());
141+
return {ip::make_address(host_info_.v4address()), host_info_.v4service_port()};
143142

144143
std::string addr = host_info_.v6address();
145144
uint16_t port = host_info_.v6service_port();
146145
lock.unlock();
147-
return udp::endpoint(resolve_v6_addr(addr), port);
146+
return {resolve_v6_addr(addr), port};
148147
}
149148

150149
std::string inlet_connection::current_uid() {

testing/ext/DataType.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
#include <lsl_cpp.h>
66
#include <thread>
77

8+
// clazy:excludeall=non-pod-global-static
9+
810
TEMPLATE_TEST_CASE(
911
"datatransfer", "[datatransfer][basic]", char, int16_t, int32_t, int64_t, float, double) {
1012
const int numBounces = sizeof(TestType) * 8;
1113
double timestamps[numBounces][2];
1214
const char *name = SampleType<TestType>::fmt_string();
13-
lsl::channel_format_t cf = (lsl::channel_format_t)SampleType<TestType>::chan_fmt;
15+
auto cf = static_cast<lsl::channel_format_t>(SampleType<TestType>::chan_fmt);
1416

1517
Streampair sp(create_streampair(
1618
lsl::stream_info(name, "Bounce", 2, lsl::IRREGULAR_RATE, cf, "streamid")));
@@ -60,8 +62,8 @@ TEST_CASE("TypeConversion", "[datatransfer][types][basic]") {
6062
Streampair sp{create_streampair(
6163
lsl::stream_info("TypeConversion", "int2str2int", 1, 1, lsl::cf_string, "TypeConversion"))};
6264
const int num_bounces = 31;
63-
std::vector<int32_t> data;
64-
for (int i = 0; i < num_bounces; ++i) data.push_back(1 << i);
65+
std::vector<int32_t> data(num_bounces);
66+
for (int i = 0; i < num_bounces; ++i) data[i] = 1 << i;
6567

6668
sp.out_.push_chunk_multiplexed(data);
6769

@@ -88,11 +90,11 @@ TEST_CASE("Flush", "[datatransfer][basic]") {
8890
}
8991
});
9092

91-
double data_in, ts_in;
92-
ts_in = sp.in_.pull_sample(&data_in, 1.);
93+
double data_in;
94+
double ts_in = sp.in_.pull_sample(&data_in, 1.);
9395
REQUIRE(ts_in == Approx(data_in));
9496
std::this_thread::sleep_for(std::chrono::milliseconds(700));
95-
int pulled = sp.in_.flush() + 1;
97+
auto pulled = sp.in_.flush() + 1;
9698

9799
for(; pulled < n; ++pulled) {
98100
INFO(pulled);

testing/ext/bench_bounce.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <catch2/catch.hpp>
44
#include <lsl_cpp.h>
55

6+
// clazy:excludeall=non-pod-global-static
7+
68
TEST_CASE("bounce", "[basic][latency]") {
79
auto sp = create_streampair(lsl::stream_info("bounce", "Test"));
810

testing/ext/bench_common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <catch2/catch.hpp>
22
#include <lsl_c.h>
33

4+
// clazy:excludeall=non-pod-global-static
5+
46
TEST_CASE("common") {
57
BENCHMARK("lsl_clock") { return lsl_local_clock(); };
68
}

testing/ext/bench_pushpull.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <string>
88
#include <thread>
99

10+
// clazy:excludeall=non-pod-global-static
11+
1012
template<typename T>
1113
struct sample_value {};
1214
template<> struct sample_value<char> { static constexpr char val = 122; };
@@ -42,12 +44,13 @@ TEMPLATE_TEST_CASE("pushpull", "[basic][throughput]", char, double, std::string)
4244

4345
BENCHMARK("push_sample_nchan_" + suffix) {
4446
for (size_t s = 0; s < chunk_size; s++) out.push_sample(data);
47+
for (auto &inlet : inlet_list) inlet.flush();
4548
};
4649

4750
BENCHMARK("push_chunk_nchan_" + suffix) {
4851
out.push_chunk_multiplexed(data, chunk_size);
52+
for (auto &inlet : inlet_list) inlet.flush();
4953
};
50-
for (auto &inlet : inlet_list) inlet.flush();
5154
}
5255
}
5356
}

testing/ext/discovery.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <lsl_cpp.h>
33
#include <thread>
44

5+
// clazy:excludeall=non-pod-global-static
6+
57
namespace {
68

79
TEST_CASE("resolve multiple streams", "[resolver][basic]") {

testing/ext/move.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <lsl_cpp.h>
33
#include <thread>
44

5+
// clazy:excludeall=non-pod-global-static
6+
57
namespace {
68

79
TEST_CASE("move C++ API types", "[move][basic]") {

testing/ext/streaminfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <lsl_cpp.h>
33
#include <thread>
44

5+
// clazy:excludeall=non-pod-global-static
6+
57
namespace {
68

79
TEST_CASE("streaminfo", "[streaminfo][basic]") {

0 commit comments

Comments
 (0)