From 29ccf5ad1ba99c269a9685bd8250db364f0587ea Mon Sep 17 00:00:00 2001 From: Luke Shingles Date: Wed, 4 Sep 2024 08:49:08 +0100 Subject: [PATCH] Fix clang-tidy 19 warnings --- .clang-tidy | 2 ++ input.cc | 4 ++-- packet.h | 2 +- ratecoeff.h | 4 ++-- rpkt.h | 2 +- sn3d.h | 6 +++--- vectors.h | 23 ++++++++++++----------- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 5573209cd..4db7639c9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -12,6 +12,7 @@ Checks: > -bugprone-easily-swappable-parameters, -bugprone-exception-escape, -bugprone-implicit-widening-of-multiplication-result, + -bugprone-multi-level-implicit-pointer-conversion, -bugprone-narrowing-conversions, -boost-use-ranges, -llvmlibc-*, @@ -39,6 +40,7 @@ Checks: > -misc-no-recursion, -misc-non-private-member-variables-in-classes, -modernize-use-ranges, + -performance-enum-size, -readability-identifier-length, -readability-function-cognitive-complexity, -readability-magic-numbers, diff --git a/input.cc b/input.cc index bcd192f6f..fa3d6c0b0 100644 --- a/input.cc +++ b/input.cc @@ -925,8 +925,8 @@ void read_phixs_data() { if (!tmpallphixs.empty()) { assert_always((nbftables * globals::NPHIXSPOINTS) == std::ssize(tmpallphixs)); - // nbftables is not large enough! This is a bug. -// copy the photoionisation tables into one contiguous block of memory + + // copy the photoionisation tables into one contiguous block of memory #ifdef MPI_ON MPI_Win win_allphixsblock = MPI_WIN_NULL; diff --git a/packet.h b/packet.h index 621cf794b..119cad317 100644 --- a/packet.h +++ b/packet.h @@ -80,7 +80,7 @@ struct Packet { int pellet_nucindex{-1}; // nuclide index of the decaying species float trueemissionvelocity{-1}; - inline auto operator==(const Packet &rhs) const -> bool { + auto operator==(const Packet &rhs) const -> bool { return (number == rhs.number && type == rhs.type && (em_pos[0] == rhs.em_pos[0] && em_pos[1] == rhs.em_pos[1] && em_pos[2] == rhs.em_pos[2]) && nu_cmf == rhs.nu_cmf && where == rhs.where && prop_time == rhs.prop_time && tdecay == rhs.tdecay && diff --git a/ratecoeff.h b/ratecoeff.h index 76fd9ce1e..b15eb3bbb 100644 --- a/ratecoeff.h +++ b/ratecoeff.h @@ -66,7 +66,7 @@ constexpr auto simpson_integrator(auto ¶ms, double a, double b, int sampleco weight = 4.; } - const double x = a + deltax * i; + const double x = a + (deltax * i); integral += weight * func_integrand(x, ¶ms) * deltax; } @@ -80,7 +80,7 @@ auto integrator(auto params, double a, double b, double epsabs, double epsrel, i double *abserr) { if constexpr (USE_SIMPSON_INTEGRATOR) { // need an odd number for Simpson rule - const int samplecount = std::max(1, static_cast((b / a) / globals::NPHIXSNUINCREMENT)) * 4 + 1; + const int samplecount = (std::max(1, static_cast((b / a) / globals::NPHIXSNUINCREMENT)) * 4) + 1; *result = simpson_integrator(params, a, b, samplecount); *abserr = 0.; diff --git a/rpkt.h b/rpkt.h index 88bb0aa4c..8960a765d 100644 --- a/rpkt.h +++ b/rpkt.h @@ -66,7 +66,7 @@ void MPI_Bcast_binned_opacities(int modelgridindex, int root_node_id); assert_testmodeonly(ion < get_nions(element) - 1); const int groundcontindex = globals::elements[element].ions[ion].groundcontindex; assert_always(groundcontindex >= 0); - return nonemptymgi * globals::nbfcontinua_ground + groundcontindex; + return (nonemptymgi * globals::nbfcontinua_ground) + groundcontindex; } inline auto keep_this_cont(int element, const int ion, const int level, const int modelgridindex, diff --git a/sn3d.h b/sn3d.h index ddd785109..59fc16424 100644 --- a/sn3d.h +++ b/sn3d.h @@ -219,7 +219,7 @@ inline void gsl_error_handler_printout(const char *reason, const char *file, int const int phixstargetindex) -> int { const int contindex = -1 - globals::elements[element].ions[ion].levels[level].cont_index + phixstargetindex; - const int bflutindex = tempindex * globals::nbfcontinua + contindex; + const int bflutindex = (tempindex * globals::nbfcontinua) + contindex; assert_testmodeonly(bflutindex >= 0); assert_testmodeonly(bflutindex <= TABLESIZE * globals::nbfcontinua); return bflutindex; @@ -321,8 +321,8 @@ constexpr auto get_range_chunk(const ptrdiff_t size, const ptrdiff_t nchunks, assert_always(nchunk >= 0); const auto minchunksize = size / nchunks; // integer division, minimum non-empty cells per process const auto n_remainder = size % nchunks; - const auto nstart = (minchunksize + 1) * std::min(n_remainder, nchunk) + - minchunksize * std::max(static_cast(0), nchunk - n_remainder); + const auto nstart = ((minchunksize + 1) * std::min(n_remainder, nchunk)) + + (minchunksize * std::max(static_cast(0), nchunk - n_remainder)); const auto nsize = (nchunk < n_remainder) ? minchunksize + 1 : minchunksize; assert_testmodeonly(nstart >= 0); assert_testmodeonly(nsize >= 0); diff --git a/vectors.h b/vectors.h index 378ba8a0f..18ae136ea 100644 --- a/vectors.h +++ b/vectors.h @@ -16,7 +16,7 @@ // return the the magnitude of a vector template [[nodiscard]] constexpr auto vec_len(const std::array &vec) -> double { - const double squaredlen = std::accumulate(vec.begin(), vec.end(), 0., [](auto a, auto b) { return a + b * b; }); + const double squaredlen = std::accumulate(vec.begin(), vec.end(), 0., [](auto a, auto b) { return a + (b * b); }); return std::sqrt(squaredlen); } @@ -89,7 +89,7 @@ template const double ndotv_on_c = dot(dir_rf, vel_rf) / CLIGHT; const double dopplerfactorsq = USE_RELATIVISTIC_DOPPLER_SHIFT ? std::pow(1. - ndotv_on_c, 2) / (1 - (dot(vel_rf, vel_rf) / CLIGHTSQUARED)) - : (1. - 2 * ndotv_on_c); + : (1. - (2 * ndotv_on_c)); assert_testmodeonly(std::isfinite(dopplerfactorsq)); assert_testmodeonly(dopplerfactorsq > 0); @@ -220,7 +220,8 @@ constexpr auto move_pkt_withtime(Packet &pkt, const double distance) -> double { // ref1_sc is the ref1 axis in the scattering plane ref1 = n1 x ( n1 x n2 ) const double n1_dot_n2 = dot(n1, n2); - auto ref1_sc = std::array{n1[0] * n1_dot_n2 - n2[0], n1[1] * n1_dot_n2 - n2[1], n1[2] * n1_dot_n2 - n2[2]}; + auto ref1_sc = + std::array{(n1[0] * n1_dot_n2) - n2[0], (n1[1] * n1_dot_n2) - n2[1], (n1[2] * n1_dot_n2) - n2[2]}; ref1_sc = vec_norm(ref1_sc); const double cos_stokes_rot_1 = std::clamp(dot(ref1_sc, ref1), -1., 1.); @@ -250,7 +251,7 @@ constexpr auto move_pkt_withtime(Packet &pkt, const double distance) -> double { [[nodiscard]] constexpr auto meridian(const std::array &n) -> std::tuple, std::array> { // for ref_1 use (from triple product rule) - const double n_xylen = std::sqrt(n[0] * n[0] + n[1] * n[1]); + const double n_xylen = std::sqrt((n[0] * n[0]) + (n[1] * n[1])); const auto ref1 = std::array{-1. * n[0] * n[2] / n_xylen, -1. * n[1] * n[2] / n_xylen, (1 - (n[2] * n[2])) / n_xylen}; @@ -285,9 +286,9 @@ constexpr auto move_pkt_withtime(Packet &pkt, const double distance) -> double { // const double v_cr_e[3] = {beta[1] * e_rf[2] - beta[2] * e_rf[1], beta[2] * e_rf[0] - beta[0] * e_rf[2], // beta[0] * e_rf[1] - beta[1] * e_rf[0]}; - const auto e_cmf = std::array{e_par[0] + gamma_rel * (e_perp[0] + v_cr_b[0]), - e_par[1] + gamma_rel * (e_perp[1] + v_cr_b[1]), - e_par[2] + gamma_rel * (e_perp[2] + v_cr_b[2])}; + const auto e_cmf = std::array{e_par[0] + (gamma_rel * (e_perp[0] + v_cr_b[0])), + e_par[1] + (gamma_rel * (e_perp[1] + v_cr_b[1])), + e_par[2] + (gamma_rel * (e_perp[2] + v_cr_b[2]))}; return vec_norm(e_cmf); } @@ -301,7 +302,7 @@ constexpr auto frame_transform(const std::array &n_rf, double *Q, dou const double U0 = *U; // Compute polarisation (which is invariant) - const double p = sqrt(Q0 * Q0 + U0 * U0); + const double p = sqrt((Q0 * Q0) + (U0 * U0)); // We want to compute the angle between ref1 and the electric field double rot_angle = 0; @@ -334,9 +335,9 @@ constexpr auto frame_transform(const std::array &n_rf, double *Q, dou // Define electric field by linear combination of ref1 and ref2 (using the angle just computed) - const auto elec_rf = std::array{cos(rot_angle) * ref1_rf[0] - sin(rot_angle) * ref2_rf[0], - cos(rot_angle) * ref1_rf[1] - sin(rot_angle) * ref2_rf[1], - cos(rot_angle) * ref1_rf[2] - sin(rot_angle) * ref2_rf[2]}; + const auto elec_rf = std::array{(cos(rot_angle) * ref1_rf[0]) - (sin(rot_angle) * ref2_rf[0]), + (cos(rot_angle) * ref1_rf[1]) - (sin(rot_angle) * ref2_rf[1]), + (cos(rot_angle) * ref1_rf[2]) - (sin(rot_angle) * ref2_rf[2])}; // Aberration const auto n_cmf = angle_ab(n_rf, v);