Skip to content

Commit 32d76a7

Browse files
authored
Make clang-tidy rules more strict (#156)
* Make clang-tidy rules more strict * Upgrade clang version on clang-tidy job to clang-18 * [CI] Fix rest of the warnings reported by clang-tidy tool
1 parent 267df47 commit 32d76a7

File tree

35 files changed

+1575
-1591
lines changed

35 files changed

+1575
-1591
lines changed

.clang-tidy

+18-37
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,31 @@
11
Checks: >
2+
bugprone-*,
3+
clang-diagnostic-*,
4+
llvm-include-order,
5+
llvm-namespace-comment,
6+
misc-*,
27
modernize-*,
38
performance-*,
49
portability-*,
510
readability-*,
11+
-bugprone-casting-through-void,
12+
-bugprone-exception-escape,
13+
-bugprone-implicit-widening-of-multiplication-result,
14+
-bugprone-narrowing-conversions,
15+
-clang-analyzer-optin.cplusplus.UninitializedObject,
16+
-misc-const-correctness,
17+
-misc-include-cleaner,
18+
-misc-no-recursion,
19+
-misc-non-private-member-variables-in-classes,
20+
-misc-unused-parameters,
21+
-misc-use-anonymous-namespace,
622
-modernize-avoid-c-arrays,
7-
-modernize-concat-nested-namespaces,
8-
-modernize-pass-by-value,
9-
-modernize-return-braced-init-list,
1023
-modernize-use-nodiscard,
1124
-modernize-use-trailing-return-type,
25+
-readability-function-cognitive-complexity,
1226
-readability-identifier-length,
1327
-readability-magic-numbers,
14-
-readability-named-parameter,
15-
-readability-redundant-declaration,
16-
bugprone-assignment-in-if-condition,
17-
bugprone-forward-declaration-namespace,
18-
bugprone-infinite-loop,
19-
bugprone-integer-division,
20-
bugprone-macro-parentheses,
21-
bugprone-macro-repeated-side-effects,
22-
bugprone-move-forwarding-reference,
23-
bugprone-redundant-branch-condition,
24-
bugprone-reserved-identifier,
25-
bugprone-suspicious-include,
26-
bugprone-suspicious-semicolon,
27-
bugprone-terminating-continue,
28-
bugprone-throw-keyword-missing,
29-
bugprone-unused-raii,
30-
bugprone-unused-return-value,
31-
clang-diagnostic-*,
32-
llvm-include-order,
33-
llvm-namespace-comment,
34-
misc-confusable-identifiers,
35-
misc-definitions-in-headers,
36-
misc-header-include-cycle,
37-
misc-include-cleaner,
38-
misc-misplaced-const,
39-
misc-non-copyable-objects,
40-
misc-redundant-expression,
41-
misc-static-assert,
42-
misc-throw-by-value-catch-by-reference,
43-
misc-unconventional-assign-operator,
44-
misc-unused-alias-decls,
45-
misc-unused-parameters,
46-
misc-unused-using-decls,
47-
misc-use-anonymous-namespace
28+
-readability-named-parameter
4829
4930
WarningsAsErrors: "*"
5031

.github/workflows/static-analysis-pr.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ jobs:
2121
id: review
2222
with:
2323
build_dir: build
24-
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-16-dev,valgrind
24+
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-18-dev,valgrind
2525
cmake_command: cmake -S . -B build -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D USE_FUNC_TESTS=ON -D USE_PERF_TESTS=ON -G Ninja -D USE_SEQ=ON -D USE_MPI=ON -D USE_OMP=ON -D USE_TBB=ON -D USE_STL=ON -D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
2626
config_file: .clang-tidy
2727
exclude: 3rdparty
2828
split_workflow: true
29+
clang_tidy_version: "18"
2930
lgtm_comment_body: ""
3031
env:
31-
CC: clang-16
32-
CXX: clang++-16
32+
CC: clang-18
33+
CXX: clang++-18
3334
- if: steps.review.outputs.total_comments > 0
3435
run: exit 1
3536
clang-tidy-for-gcc-build:
@@ -46,11 +47,12 @@ jobs:
4647
id: review
4748
with:
4849
build_dir: build
49-
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-16-dev,valgrind
50+
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-18-dev,valgrind
5051
cmake_command: cmake -S . -B build -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -G Ninja -D USE_FUNC_TESTS=ON -D USE_PERF_TESTS=ON -D USE_SEQ=ON -D USE_MPI=ON -D USE_OMP=ON -D USE_TBB=ON -D USE_STL=ON -D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
5152
config_file: .clang-tidy
5253
exclude: 3rdparty
5354
split_workflow: true
55+
clang_tidy_version: "18"
5456
lgtm_comment_body: ""
5557
- if: steps.review.outputs.total_comments > 0
5658
run: |

1stsamples/mpi/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ int main(int argc, char** argv) {
1616
MPI_Get_processor_name(processor_name, &len_chars);
1717

1818
MPI_Barrier(MPI_COMM_WORLD);
19-
std::cout << "Processor = " << processor_name << std::endl;
20-
std::cout << "Rank = " << world_rank << std::endl;
21-
std::cout << "Number of processors = " << world_size << std::endl;
19+
std::cout << "Processor = " << processor_name << '\n';
20+
std::cout << "Rank = " << world_rank << '\n';
21+
std::cout << "Number of processors = " << world_size << '\n';
2222

2323
MPI_Finalize();
2424
return 0;

1stsamples/mpi_boost/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ int main(int argc, char** argv) {
1111
boost::mpi::communicator world;
1212

1313
world.barrier();
14-
std::cout << "Processor = " << boost::mpi::environment::processor_name() << std::endl;
15-
std::cout << "Rank = " << world.rank() << std::endl;
16-
std::cout << "Number of processors = " << world.size() << std::endl;
14+
std::cout << "Processor = " << boost::mpi::environment::processor_name() << '\n';
15+
std::cout << "Rank = " << world.rank() << '\n';
16+
std::cout << "Number of processors = " << world.size() << '\n';
1717

1818
return 0;
1919
}

1stsamples/omp/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
int main() {
66
#pragma omp parallel
77
{
8-
std::cout << "Thread number = " << omp_get_thread_num() << std::endl;
9-
std::cout << "Number of threads = " << omp_get_num_threads() << std::endl;
8+
std::cout << "Thread number = " << omp_get_thread_num() << '\n';
9+
std::cout << "Number of threads = " << omp_get_num_threads() << '\n';
1010
}
1111
return 0;
1212
}

1stsamples/stl/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#include <thread>
44
#include <vector>
55

6-
void task(const std::string& msg) { std::cout << "thread number: " + msg << std::endl; }
6+
static void Task(const std::string& msg) { std::cout << "thread number: " + msg << '\n'; }
77

88
int main() {
99
const auto num_max_threads = std::thread::hardware_concurrency();
10-
std::cout << "Number of threads = " << num_max_threads << std::endl;
10+
std::cout << "Number of threads = " << num_max_threads << '\n';
1111
std::vector<std::thread> thr(num_max_threads);
1212

1313
for (unsigned int i = 0; i < num_max_threads; ++i) {
14-
thr[i] = std::thread(task, std::to_string(i));
14+
thr[i] = std::thread(Task, std::to_string(i));
1515
}
1616

1717
for (unsigned int i = 0; i < num_max_threads; ++i) {

1stsamples/tbb/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
#include <iostream>
44

5-
int fib_func(int n) {
5+
static int FibFunc(int n) {
66
if (n < 2) {
77
return n;
88
}
99
int x;
1010
int y;
1111
oneapi::tbb::task_group g;
12-
g.run([&] { x = fib_func(n - 1); });
13-
g.run([&] { y = fib_func(n - 2); });
12+
g.run([&] { x = FibFunc(n - 1); });
13+
g.run([&] { y = FibFunc(n - 2); });
1414
g.wait();
1515
return x + y;
1616
}
1717

18-
int main() { return fib_func(10) - 55; }
18+
int main() { return FibFunc(10) - 55; }

0 commit comments

Comments
 (0)