From 5c78e6cf94b233f37be12e03ea5e689e574a5e31 Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Mon, 9 Sep 2024 22:59:03 +0200 Subject: [PATCH] Add readability-else-after-return check --- .clang-tidy | 2 +- .../kernels/splines/spline_boundary_conditions.hpp | 4 +++- .../splines/splines_linear_problem_2x2_blocks.hpp | 12 ++++++++---- .../kernels/splines/splines_linear_problem_band.hpp | 4 ++-- .../kernels/splines/splines_linear_problem_maker.hpp | 12 ++++++++---- .../splines/splines_linear_problem_pds_band.hpp | 5 +++-- .../splines/splines_linear_problem_pds_tridiag.hpp | 5 +++-- 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 3faa5e01c..6c3bd0186 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,5 +2,5 @@ # # SPDX-License-Identifier: MIT --- -Checks: '-*,bugprone-branch-clone,bugprone-reserved-identifier,hicpp-avoid-c-arrays,misc-const-correctness,modernize-use-nullptr,readability-avoid-const-params-in-decls' +Checks: '-*,bugprone-branch-clone,bugprone-reserved-identifier,hicpp-avoid-c-arrays,misc-const-correctness,modernize-use-nullptr,readability-avoid-const-params-in-decls,readability-else-after-return' WarningsAsErrors: '*' diff --git a/include/ddc/kernels/splines/spline_boundary_conditions.hpp b/include/ddc/kernels/splines/spline_boundary_conditions.hpp index 66cc30b54..739f99392 100644 --- a/include/ddc/kernels/splines/spline_boundary_conditions.hpp +++ b/include/ddc/kernels/splines/spline_boundary_conditions.hpp @@ -53,7 +53,9 @@ constexpr int n_boundary_equations(ddc::BoundCond const bc, std::size_t const de { if (bc == ddc::BoundCond::PERIODIC || bc == ddc::BoundCond::GREVILLE) { return 0; - } else if (bc == ddc::BoundCond::HERMITE) { + } + + if (bc == ddc::BoundCond::HERMITE) { return degree / 2; } diff --git a/include/ddc/kernels/splines/splines_linear_problem_2x2_blocks.hpp b/include/ddc/kernels/splines/splines_linear_problem_2x2_blocks.hpp index a3256a38c..53649229b 100644 --- a/include/ddc/kernels/splines/splines_linear_problem_2x2_blocks.hpp +++ b/include/ddc/kernels/splines/splines_linear_problem_2x2_blocks.hpp @@ -151,13 +151,17 @@ class SplinesLinearProblem2x2Blocks : public SplinesLinearProblem std::size_t const nq = m_top_left_block->size(); if (i < nq && j < nq) { return m_top_left_block->get_element(i, j); - } else if (i >= nq && j >= nq) { + } + + if (i >= nq && j >= nq) { return m_bottom_right_block->get_element(i - nq, j - nq); - } else if (j >= nq) { + } + + if (j >= nq) { return m_top_right_block.h_view(i, j - nq); - } else { - return m_bottom_left_block.h_view(i - nq, j); } + + return m_bottom_left_block.h_view(i - nq, j); } void set_element(std::size_t const i, std::size_t const j, double const aij) override diff --git a/include/ddc/kernels/splines/splines_linear_problem_band.hpp b/include/ddc/kernels/splines/splines_linear_problem_band.hpp index bd7c6b8bb..2ddcc87a7 100644 --- a/include/ddc/kernels/splines/splines_linear_problem_band.hpp +++ b/include/ddc/kernels/splines/splines_linear_problem_band.hpp @@ -105,9 +105,9 @@ class SplinesLinearProblemBand : public SplinesLinearProblem static_cast(j) - static_cast(m_ku)) && i < std::min(size(), j + m_kl + 1)) { return m_q.h_view(band_storage_row_index(i, j), j); - } else { - return 0.0; } + + return 0.0; } void set_element(std::size_t const i, std::size_t const j, double const aij) override diff --git a/include/ddc/kernels/splines/splines_linear_problem_maker.hpp b/include/ddc/kernels/splines/splines_linear_problem_maker.hpp index 712223c72..f8181211e 100644 --- a/include/ddc/kernels/splines/splines_linear_problem_maker.hpp +++ b/include/ddc/kernels/splines/splines_linear_problem_maker.hpp @@ -61,13 +61,17 @@ class SplinesLinearProblemMaker { if (kl == ku && kl == 1 && pds) { return std::make_unique>(n); - } else if (kl == ku && pds) { + } + + if (kl == ku && pds) { return std::make_unique>(n, kl); - } else if (2 * kl + ku + 1 >= n) { + } + + if (2 * kl + ku + 1 >= n) { return std::make_unique>(n); - } else { - return std::make_unique>(n, kl, ku); } + + return std::make_unique>(n, kl, ku); } /** diff --git a/include/ddc/kernels/splines/splines_linear_problem_pds_band.hpp b/include/ddc/kernels/splines/splines_linear_problem_pds_band.hpp index 77ac1e096..712af217c 100644 --- a/include/ddc/kernels/splines/splines_linear_problem_pds_band.hpp +++ b/include/ddc/kernels/splines/splines_linear_problem_pds_band.hpp @@ -75,11 +75,12 @@ class SplinesLinearProblemPDSBand : public SplinesLinearProblem if (i > j) { std::swap(i, j); } + if (j - i < m_q.extent(0)) { return m_q.h_view(j - i, i); - } else { - return 0.0; } + + return 0.0; } void set_element(std::size_t i, std::size_t j, double const aij) override diff --git a/include/ddc/kernels/splines/splines_linear_problem_pds_tridiag.hpp b/include/ddc/kernels/splines/splines_linear_problem_pds_tridiag.hpp index 0be7a7682..ac2da4f39 100644 --- a/include/ddc/kernels/splines/splines_linear_problem_pds_tridiag.hpp +++ b/include/ddc/kernels/splines/splines_linear_problem_pds_tridiag.hpp @@ -73,11 +73,12 @@ class SplinesLinearProblemPDSTridiag : public SplinesLinearProblem if (i > j) { std::swap(i, j); } + if (j - i < 2) { return m_q.h_view(j - i, i); - } else { - return 0.0; } + + return 0.0; } void set_element(std::size_t i, std::size_t j, double const aij) override