Skip to content

Commit cab6e02

Browse files
committed
Introduce clang-tidy and fix diagnostics
Signed-off-by: Philipp Jungkamp <[email protected]>
1 parent bf6ea2f commit cab6e02

File tree

225 files changed

+1047
-1095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+1047
-1095
lines changed

.clang-tidy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, RWTH Aachen University
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
Checks: >
5+
-*,
6+
modernize-use-override,
7+
misc-const-correctness,
8+
WarningsAsErrors: '*'
9+
HeaderFilterRegex: villas/.*
10+
FormatStyle: file

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ include(FindSymbol)
5353
include(CMakeDependentOption)
5454

5555
add_definitions(-D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE)
56-
add_compile_options(-Wall -Wno-unknown-pragmas -fdiagnostics-color=auto)
56+
add_compile_options(
57+
-Wall
58+
-Wno-unknown-pragmas
59+
-Wno-vla-cxx-extension
60+
-Wno-unused-command-line-argument
61+
-fdiagnostics-color=auto
62+
)
5763

5864
# Check OS
5965
check_include_file("sys/eventfd.h" HAS_EVENTFD)

clients/shmem/villas-shmem.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Shmem : public Tool {
3434
protected:
3535
std::atomic<bool> stop;
3636

37-
void usage() {
37+
void usage() override {
3838
std::cout
3939
<< "Usage: villas-test-shmem WNAME VECTORIZE" << std::endl
4040
<< " WNAME name of the shared memory object for the output queue"
@@ -47,9 +47,9 @@ class Shmem : public Tool {
4747
printCopyright();
4848
}
4949

50-
void handler(int, siginfo_t *, void *) { stop = true; }
50+
void handler(int, siginfo_t *, void *) override { stop = true; }
5151

52-
int main() {
52+
int main() override {
5353
int ret, readcnt, writecnt, avail;
5454

5555
struct ShmemInterface shm;
@@ -62,9 +62,9 @@ class Shmem : public Tool {
6262
return 1;
6363
}
6464

65-
std::string wname = argv[1];
66-
std::string rname = argv[2];
67-
int vectorize = atoi(argv[3]);
65+
std::string const wname = argv[1];
66+
std::string const rname = argv[2];
67+
int const vectorize = atoi(argv[3]);
6868

6969
ret = shmem_int_open(wname.c_str(), rname.c_str(), &shm, &conf);
7070
if (ret < 0)
@@ -87,7 +87,7 @@ class Shmem : public Tool {
8787
outsmps[i]->sequence = insmps[i]->sequence;
8888
outsmps[i]->ts = insmps[i]->ts;
8989

90-
int len = MIN(insmps[i]->length, outsmps[i]->capacity);
90+
int const len = MIN(insmps[i]->length, outsmps[i]->capacity);
9191
memcpy(outsmps[i]->data, insmps[i]->data, SAMPLE_DATA_LENGTH(len));
9292

9393
outsmps[i]->length = len;

common/include/villas/cpuset.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CpuSet {
7575
size_t size() const { return sz; }
7676

7777
CpuSet operator~() {
78-
CpuSet full = UINTMAX_MAX;
78+
CpuSet const full = UINTMAX_MAX;
7979

8080
return full ^ *this;
8181
}

common/include/villas/dsp/window_cosine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CosineWindow : public Window<T> {
2727

2828
T correctionFactor;
2929

30-
virtual T filter(T in, size_type i) const { return in * coefficients[i]; }
30+
T filter(T in, size_type i) const override { return in * coefficients[i]; }
3131

3232
public:
3333
CosineWindow(double a0, double a1, double a2, double a3, double a4,

common/include/villas/exceptions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ConfigError : public std::runtime_error {
9292
}
9393

9494
public:
95-
~ConfigError() {
95+
~ConfigError() override {
9696
if (msg)
9797
free(msg);
9898
}
@@ -132,12 +132,12 @@ class ConfigError : public std::runtime_error {
132132
}
133133

134134
std::string docUri() const {
135-
std::string baseUri = "https://villas.fein-aachen.org/doc/jump?";
135+
std::string const baseUri = "https://villas.fein-aachen.org/doc/jump?";
136136

137137
return baseUri + id;
138138
}
139139

140-
virtual const char *what() const noexcept { return msg; }
140+
const char *what() const noexcept override { return msg; }
141141
};
142142

143143
} // namespace villas

common/include/villas/graph/directed.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DirectedGraph {
100100
EdgeIdentifier addDefaultEdge(VertexIdentifier fromVertexId,
101101
VertexIdentifier toVertexId) {
102102
// Create a new edge
103-
std::shared_ptr<EdgeType> edge(new EdgeType);
103+
std::shared_ptr<EdgeType> const edge(new EdgeType);
104104

105105
return addEdge(edge, fromVertexId, toVertexId);
106106
}

common/include/villas/kernel/devices/driver.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Driver {
2424
virtual std::string name() const = 0;
2525
virtual void override(const Device &device) const = 0;
2626
virtual void unbind(const Device &device) const = 0;
27+
virtual ~Driver() {}
2728
};
2829

2930
} // namespace devices

common/include/villas/kernel/vfio_device.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
#pragma once
1313

14-
#include <list>
15-
#include <memory>
1614
#include <string>
1715
#include <vector>
1816

@@ -99,7 +97,7 @@ class Device {
9997
std::vector<void *> mappings;
10098

10199
// libpci handle of the device
102-
const kernel::devices::PciDevice *pci_device;
100+
[[maybe_unused]] const kernel::devices::PciDevice *pci_device;
103101

104102
Logger log;
105103
};

common/include/villas/memory.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ template <typename DerivedAllocator> class BaseAllocator {
116116
: memoryAddrSpaceId(memoryAddrSpaceId) {
117117
// CRTP
118118
derivedAlloc = static_cast<DerivedAllocator *>(this);
119-
std::string loggerName = fmt::format("memory:", derivedAlloc->getName());
119+
std::string const loggerName =
120+
fmt::format("memory:", derivedAlloc->getName());
120121
logger = Log::get(loggerName);
121122

122123
// Default deallocation callback
@@ -136,7 +137,6 @@ template <typename DerivedAllocator> class BaseAllocator {
136137
}
137138

138139
virtual std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
139-
140140
allocateBlock(size_t size) = 0;
141141

142142
template <typename T> MemoryAccessor<T> allocate(size_t num) {
@@ -152,7 +152,7 @@ template <typename DerivedAllocator> class BaseAllocator {
152152
// Check if the allocated memory is really accessible by writing to the
153153
// allocated memory and reading back. Exponentially increase offset to
154154
// speed up testing.
155-
MemoryAccessor<volatile uint8_t> byteAccessor(*mem);
155+
MemoryAccessor<volatile uint8_t> const byteAccessor(*mem);
156156
size_t idx = 0;
157157
for (int i = 0; idx < mem->getSize(); i++, idx = (1 << i)) {
158158
auto val = static_cast<uint8_t>(i);
@@ -166,6 +166,8 @@ template <typename DerivedAllocator> class BaseAllocator {
166166
return MemoryAccessor<T>(std::move(mem));
167167
}
168168

169+
virtual ~BaseAllocator() {}
170+
169171
protected:
170172
void insertMemoryBlock(const MemoryBlock &mem) {
171173
auto &mm = MemoryManager::get();
@@ -217,8 +219,8 @@ class LinearAllocator : public BaseAllocator<LinearAllocator> {
217219

218220
std::string getName() const;
219221

220-
virtual std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
221-
allocateBlock(size_t size);
222+
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
223+
allocateBlock(size_t size) override;
222224

223225
private:
224226
static constexpr size_t alignBytes = sizeof(uintptr_t);
@@ -247,7 +249,7 @@ class HostRam {
247249
std::string getName() const { return "HostRamAlloc"; }
248250

249251
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
250-
allocateBlock(size_t size);
252+
allocateBlock(size_t size) override;
251253
};
252254

253255
static HostRamAllocator &getAllocator() {
@@ -264,7 +266,7 @@ class HostDmaRam {
264266
public:
265267
HostDmaRamAllocator(int num);
266268

267-
virtual ~HostDmaRamAllocator();
269+
~HostDmaRamAllocator() override;
268270

269271
std::string getName() const { return getUdmaBufName(num); }
270272

0 commit comments

Comments
 (0)