Fix clang-tidy warnings for clang 7
authorRoland Schulz <roland.schulz@intel.com>
Wed, 19 Sep 2018 19:57:15 +0000 (12:57 -0700)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 21 Sep 2018 08:08:28 +0000 (10:08 +0200)
Disable clang-analyzer because we run analyzer as seperate job.
Disable cppcoreguidelines-avoid-goto because it is easy to spot
in code-review and has very rare good uses.

Change-Id: Ibfeb8ba6b14012b0079e7eef15282e0e2b6538fc

38 files changed:
admin/builds/pre-submit-matrix.txt
docs/dev-manual/tools.rst
src/.clang-tidy
src/.clang-tidy.new.code
src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/awh/grid.cpp
src/gromacs/awh/tests/bias.cpp
src/gromacs/commandline/pargs.cpp
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/fileio/matio.cpp
src/gromacs/fileio/pdbio.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_genion.cpp
src/gromacs/gmxana/gmx_msd.cpp
src/gromacs/gmxana/gmx_trjcat.cpp
src/gromacs/gmxana/pp2shift.cpp
src/gromacs/gmxlib/nonbonded/.clang-tidy
src/gromacs/gmxpreprocess/pdb2top.cpp
src/gromacs/hardware/identifyavx512fmaunits.cpp
src/gromacs/listed-forces/pairs.cpp
src/gromacs/listed-forces/position-restraints.cpp
src/gromacs/math/functions.h
src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_gpu_ref.cpp
src/gromacs/pulling/pullutil.cpp
src/gromacs/selection/params.cpp
src/gromacs/selection/selelem.cpp
src/gromacs/simd/scalar/scalar.h
src/gromacs/tables/cubicsplinetable.cpp
src/gromacs/tables/quadraticsplinetable.cpp
src/gromacs/tables/splineutil.cpp
src/gromacs/topology/atomprop.cpp
src/gromacs/trajectoryanalysis/runnercommon.cpp
src/gromacs/utility/bitmask.h
src/gromacs/utility/futil.cpp
src/gromacs/utility/stringutil.cpp
src/programs/mdrun/tests/rerun.cpp
src/testutils/testasserts.h

index 82c377d47aea1dc713db72c2a80d3671d61a3578..b0127e8a7f7adaf05a1a9a13f4bcb16a0edace2c 100644 (file)
@@ -62,7 +62,7 @@ clang-7 no-openmp asan cmake-3.11.4
 
 # Test newest cmake at time of release
 # Test with clang-tidy (without OpenMP, cmake>=3.6)
-clang-6 no-openmp cmake-3.12.1 tidy
+clang-7 no-openmp cmake-3.12.1 tidy
 
 # Test oldest supported MSVC on Windows
 # Test newest supported MSVC on Windows
index 979c381c9060ddee93d5818048738e594985d745..401a09410963188880e0ed309ece5808d1421944 100644 (file)
@@ -82,10 +82,10 @@ unit testing (CTest)
 regression tests
 
 clang-tidy
-  `clang-tidy <http://releases.llvm.org/6.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
+  `clang-tidy <http://releases.llvm.org/7.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
   is used for static code analysis. clang-tidy is easy to install. It is contained in
   the llvm binary `package <http://releases.llvm.org/download.html#6.0.0>`_. Only
-  version 6.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
+  version 7.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
   It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be
   applied. To run it, the build has to be configured with
   ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``.
index 21b88ea02602a8f3b7c23137fe0b748e8aab08f0..20be0b77f7be9e9af9155b8fcabf2578a9e89b0f 100644 (file)
@@ -1,4 +1,4 @@
-Checks:  clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
+Checks:  clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
          bugprone-*,misc-*,readability-*,performance-*,mpi-*,
          -readability-inconsistent-declaration-parameter-name,
          -readability-function-size,-readability-else-after-return,
@@ -9,6 +9,7 @@ Checks:  clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAP
          modernize-redundant-void-arg,modernize-use-bool-literals,
          cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory,
          -cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
+         -cppcoreguidelines-avoid-goto,
          google-*,-google-build-using-namespace,-google-explicit-constructor,
          -google-readability-function-size,-google-readability-todo,-google-runtime-int
 HeaderFilterRegex: .*
index 5558050fd1e2186af97801ee8dbaa217ea721de2..e495372d9b597af5828bab8719f8ee195b8b7743 100644 (file)
@@ -1,4 +1,4 @@
-Checks:  clang-diagnostic-*,clang-analyzer-*,
+Checks:  clang-diagnostic-*,-clang-analyzer-*,
          bugprone-*,misc-*,readability-*,performance-*,mpi-*,-misc-incorrect-roundings,
          -readability-else-after-return,
          modernize-use-nullptr,modernize-use-emplace,
@@ -12,6 +12,7 @@ Checks:  clang-diagnostic-*,clang-analyzer-*,
          -cppcoreguidelines-pro-bounds-constant-array-index,
          -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
          -cppcoreguidelines-pro-bounds-pointer-arithmetic,
+         -cppcoreguidelines-avoid-goto,
          google-*,-google-build-using-namespace,-google-explicit-constructor,
          -google-readability-todo,
          -google-runtime-int
index 03659c2b144534a2c8e93365c1bc311d3499301d..25eccc9bd4d06b1ad11ee8bdfc6c15575510f698 100644 (file)
@@ -336,7 +336,7 @@ AbstractPlotModule::dataStarted(AbstractAnalysisData * /* data */)
         else
         {
             time_unit_t  time_unit
-                = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1); // NOLINT(misc-misplaced-widening-cast)
+                = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1); // NOLINT(bugprone-misplaced-widening-cast)
             xvg_format_t xvg_format
                 = (impl_->settings_.plotFormat() > 0
                    ? static_cast<xvg_format_t>(impl_->settings_.plotFormat())
index 7b6492791f0818916958c9d8569a550abc19f90c..737b31f4f2268354a3f5c19a055989ffbfb56526 100644 (file)
@@ -209,12 +209,10 @@ void linearArrayIndexToMultiDim(int indexLinear, int numDimensions, const awh_iv
         int stride = 1;
 
         /* Workaround for bug in clang */
-#ifndef __clang_analyzer__
         for (int k = d + 1; k < numDimensions; k++)
         {
             stride *= numPointsDim[k];
         }
-#endif
 
         indexMulti[d] = indexLinear/stride;
         indexLinear  -= indexMulti[d]*stride;
index 033ad06d2276683d812689d8d80afa0db72ee26a..84fa8bf22d6db2971ad17200dbcc3fc22818da2c 100644 (file)
@@ -266,9 +266,9 @@ TEST_P(BiasTest, ForcesBiasPmf)
      * In taking this deviation we lose a lot of precision, so we should
      * compare against k*max(coord) instead of the instantaneous force.
      */
-    const double kCoordMax = bias.dimParams()[0].k*coordMaxValue;
+    const double  kCoordMax = bias.dimParams()[0].k*coordMaxValue;
 
-    const double ulpTol    = 10;
+    constexpr int ulpTol    = 10;
 
     checker.checkSequence(props.begin(),     props.end(),     "Properties");
     checker.setDefaultTolerance(absoluteTolerance(kCoordMax*GMX_DOUBLE_EPS*ulpTol));
index 87a602ca65324869995b98fd2e81c8e4f777f584..0804bbb7badad0389c071001e4bfedf02b4847f8 100644 (file)
@@ -566,7 +566,7 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
 
         /* set program name, command line, and default values for output options */
         output_env_init(oenv, gmx::getProgramContext(),
-                        static_cast<time_unit_t>(timeUnit + 1), bView, // NOLINT(misc-misplaced-widening-cast)
+                        static_cast<time_unit_t>(timeUnit + 1), bView, // NOLINT(bugprone-misplaced-widening-cast)
                         static_cast<xvg_format_t>(xvgFormat + 1), 0);
 
         /* Extract Time info from arguments */
index b86d93d23e1217de80280245a2e4c1843256f086..04966c882f546e1f225805e7500370faca91f799 100644 (file)
@@ -699,7 +699,7 @@ static gmx_reverse_top_t make_reverse_top(const gmx_mtop_t *mtop, gmx_bool bFE,
         atoms_global.nr   = mtop->natoms;
         atoms_global.atom = nullptr; /* Only used with virtual sites */
 
-        GMX_RELEASE_ASSERT(mtop->intermolecular_ilist.get(), "We should have an ilist when intermolecular interactions are on");
+        GMX_RELEASE_ASSERT(mtop->intermolecular_ilist, "We should have an ilist when intermolecular interactions are on");
 
         *nint +=
             make_reverse_ilist(*mtop->intermolecular_ilist,
@@ -2281,7 +2281,7 @@ t_blocka *make_charge_group_links(const gmx_mtop_t *mtop, gmx_domdec_t *dd,
         atoms.nr   = mtop->natoms;
         atoms.atom = nullptr;
 
-        GMX_RELEASE_ASSERT(mtop->intermolecular_ilist.get(), "We should have an ilist when intermolecular interactions are on");
+        GMX_RELEASE_ASSERT(mtop->intermolecular_ilist, "We should have an ilist when intermolecular interactions are on");
 
         make_reverse_ilist(*mtop->intermolecular_ilist,
                            &atoms,
@@ -2702,7 +2702,7 @@ void dd_bonded_cg_distance(const gmx::MDLogger &mdlog,
             gmx_fatal(FARGS, "The combination of intermolecular interactions, charge groups and domain decomposition is not supported. Use cutoff-scheme=Verlet (which removes the charge groups) or run without domain decomposition.");
         }
 
-        GMX_RELEASE_ASSERT(mtop->intermolecular_ilist.get(), "We should have an ilist when intermolecular interactions are on");
+        GMX_RELEASE_ASSERT(mtop->intermolecular_ilist, "We should have an ilist when intermolecular interactions are on");
 
         bonded_distance_intermol(*mtop->intermolecular_ilist,
                                  bBCheck,
index 25876f808140f384c4c9dcd31304b076fa473da6..129ae67d63d91155491d8f34ddc31ceb363838ab 100644 (file)
@@ -47,6 +47,7 @@
 #include <string>
 
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/math/functions.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/utility/binaryinformation.h"
 #include "gromacs/utility/cstringutil.h"
@@ -879,7 +880,7 @@ static void write_xpm_data(FILE *out, int n_x, int n_y, real **mat,
         fprintf(out, "\"");
         for (i = 0; (i < n_x); i++)
         {
-            c = std::round((mat[i][j]-lo)*invlevel);
+            c = gmx::roundToInt((mat[i][j]-lo)*invlevel);
             if (c < 0)
             {
                 c = 0;
@@ -929,11 +930,11 @@ static void write_xpm_data3(FILE *out, int n_x, int n_y, real **mat,
         {
             if (mat[i][j] >= mid)
             {
-                c = nmid+std::round((mat[i][j]-mid)*invlev_hi);
+                c = nmid+gmx::roundToInt((mat[i][j]-mid)*invlev_hi);
             }
             else if (mat[i][j] >= lo)
             {
-                c = std::round((mat[i][j]-lo)*invlev_lo);
+                c = gmx::roundToInt((mat[i][j]-lo)*invlev_lo);
             }
             else
             {
@@ -989,7 +990,7 @@ static void write_xpm_data_split(FILE *out, int n_x, int n_y, real **mat,
         {
             if (i < j)
             {
-                c = nlevel_bot+std::round((mat[i][j]-lo_top)*invlev_top);
+                c = nlevel_bot+gmx::roundToInt((mat[i][j]-lo_top)*invlev_top);
                 if ((c < nlevel_bot) || (c >= nlevel_bot+nlevel_top))
                 {
                     gmx_fatal(FARGS, "Range checking i = %d, j = %d, c = %d, bot = %d, top = %d matrix[i,j] = %f", i, j, c, nlevel_bot, nlevel_top, mat[i][j]);
@@ -997,7 +998,7 @@ static void write_xpm_data_split(FILE *out, int n_x, int n_y, real **mat,
             }
             else if (i > j)
             {
-                c = std::round((mat[i][j]-lo_bot)*invlev_bot);
+                c = gmx::roundToInt((mat[i][j]-lo_bot)*invlev_bot);
                 if ((c < 0) || (c >= nlevel_bot+nlevel_bot))
                 {
                     gmx_fatal(FARGS, "Range checking i = %d, j = %d, c = %d, bot = %d, top = %d matrix[i,j] = %f", i, j, c, nlevel_bot, nlevel_top, mat[i][j]);
index aa070856c64c43f172127cfd4e5bb1b77e6518ee..48dc48d246f23fce6caaa61b380b46a185440db9 100644 (file)
@@ -588,7 +588,7 @@ void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
             anm_copy[2] = nc;
             if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
             {
-                atomnumber    = std::round(eval);
+                atomnumber    = gmx::roundToInt(eval);
                 atomNumberSet = true;
             }
             else
@@ -596,7 +596,7 @@ void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
                 anm_copy[1] = nc;
                 if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
                 {
-                    atomnumber    = std::round(eval);
+                    atomnumber    = gmx::roundToInt(eval);
                     atomNumberSet = true;
                 }
             }
@@ -612,7 +612,7 @@ void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
             anm_copy[1] = nc;
             if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
             {
-                atomnumber    = std::round(eval);
+                atomnumber    = gmx::roundToInt(eval);
                 atomNumberSet = true;
             }
         }
index 5fe85b58a243989c9fe8c4818ff249beb3d91ab5..095aa2da37d3f309a5a4f725d0e7f9754ec794e0 100644 (file)
@@ -137,7 +137,7 @@ static void done_gkrbin(t_gkrbin **gb)
 
 static void add2gkr(t_gkrbin *gb, real r, real cosa, real phi)
 {
-    int  cy, index = std::round(r/gb->spacing);
+    int  cy, index = gmx::roundToInt(r/gb->spacing);
     real alpha;
 
     if (index < gb->nelem)
index 871d020255f7db7b226da5374bcb61381c53015a..1190caa175b0457bc5d85e4580303b81d2543395 100644 (file)
@@ -430,14 +430,14 @@ int gmx_genion(int argc, char *argv[])
     {
         qtot += atoms.atom[i].q;
     }
-    iqtot = std::round(qtot);
+    iqtot = gmx::roundToInt(qtot);
 
 
     if (conc > 0)
     {
         /* Compute number of ions to be added */
         vol   = det(box);
-        nsalt = std::round(conc*vol*AVOGADRO/1e24);
+        nsalt = gmx::roundToInt(conc*vol*AVOGADRO/1e24);
         p_num = abs(nsalt*n_q);
         n_num = abs(nsalt*p_q);
     }
index 8c54f617e68da123a37431f6648c58a38deb5a72..ec7feb678f3c5790602819a41d4160b14025df60 100644 (file)
@@ -884,7 +884,7 @@ static void do_corr(const char *trx_file, const char *ndx_file, const char *msd_
     char         **grpname;
     int            i, i0, i1, j, N, nat_trx;
     real          *DD, *SigmaD, a, a2, b, r, chi2;
-    rvec          *x;
+    rvec          *x = nullptr;
     matrix         box;
     int           *gnx_com     = nullptr; /* the COM removal group size  */
     int          **index_com   = nullptr; /* the COM removal group atom indices */
index 9d5ed554e24523ca991da40de3985aba85384aad..144892a765638a07b0f58e78a4a3b31bf99a410a 100644 (file)
@@ -370,7 +370,7 @@ static void do_demux(gmx::ArrayRef<const std::string> inFiles,
         }
         for (gmx::index i = 0; i < inFiles.size(); i++)
         {
-            int j = std::round(value[i][k]);
+            int j = gmx::roundToInt(value[i][k]);
             range_check(j, 0, inFiles.size());
             if (bSet[j])
             {
index da2589d653886dcb188f653781b61a49863d6386..b05ff8c2d14f3af3d0be61d08429e410dc6f28c0 100644 (file)
@@ -160,7 +160,7 @@ static t_shiftdata *read_shifts(const char *fn)
     {
         gmx_fatal(FARGS, "Error reading from file %s", fn);
     }
-
+    GMX_ASSERT(nx > 0, "");
     sd->nx = nx;
     sd->ny = ny;
     sd->dx = nx/(2*M_PI);
index de0482b7219d6dc0208cad153517064d17db54dd..2a87d8112cce3c8bb543130a2bca5ba2603cb290 100644 (file)
@@ -1 +1 @@
-Checks: -*
+Checks: -modernize-*
index b44f0666f0892960dcf24a327ba8176486bf6bfb..8ed41d9f45fd068737e8543a8929420b13acb7f8 100644 (file)
@@ -125,7 +125,7 @@ bool is_int(double x)
     {
         x = -x;
     }
-    ix = std::round(x);
+    ix = gmx::roundToInt(x);
 
     return (fabs(x-ix) < tol);
 }
index 8eabb5784fe2fdc50ad3540c8c15ab939c0f756c..a5a3b6dc751492e59c77c4d8e65a33c5cdb4006c 100644 (file)
@@ -227,7 +227,7 @@ timeFmaOnlyLoop(uint64_t loopCount)
 bool
 checkDualAvx512FmaUnits()
 {
-    uint64_t timeFmaAndShuf = 1e9;             // Large value
+    uint64_t timeFmaAndShuf = static_cast<uint64_t>(1e9);             // Large value
 
     // Make sure the CPU is in AVX512 mode by executing a fairly long loop.
     // Use the return value to make sure it is not optimized away. Later invocations
index c48d05afe724132b2cfa31c61ff9c766eebd161f..8de6b30d4a91ecf2f639ac78db9114a68db37409 100644 (file)
@@ -108,7 +108,7 @@ evaluate_single(real r2, real tabscale, const real *vftab, real tableStride,
     ntab             = static_cast<int>(rtab);
     eps              = rtab-ntab;
     eps2             = eps*eps;
-    ntab             = tableStride*ntab;
+    ntab             = static_cast<int>(tableStride*ntab);
     /* Electrostatics */
     Y                = vftab[ntab];
     F                = vftab[ntab+1];
@@ -264,7 +264,7 @@ free_energy_evaluate_single(real r2, real sc_r_power, real alpha_coul,
             ntab             = static_cast<int>(rtab);
             eps              = rtab-ntab;
             eps2             = eps*eps;
-            ntab             = tableStride*ntab;
+            ntab             = static_cast<int>(tableStride*ntab);
             /* Electrostatics */
             Y                = vftab[ntab];
             F                = vftab[ntab+1];
index 280bcd4aeb59ab358c9697f9d450756c964f30b3..0fa2a2fed8cfd4e00faef9a406fd90b415c97a78 100644 (file)
@@ -199,7 +199,7 @@ real fbposres(int nbonds,
     gmx_bool         bInvert;
 
     npbcdim = ePBC2npbcdim(ePBC);
-
+    GMX_ASSERT((ePBC == epbcNONE) ==  (npbcdim == 0), "");
     if (refcoord_scaling == erscCOM)
     {
         clear_rvec(com_sc);
@@ -329,7 +329,7 @@ real posres(int nbonds,
     rvec             comA_sc, comB_sc, rdist, dpdl, dx;
 
     npbcdim = ePBC2npbcdim(ePBC);
-
+    GMX_ASSERT((ePBC == epbcNONE) ==  (npbcdim == 0), "");
     if (refcoord_scaling == erscCOM)
     {
         clear_rvec(comA_sc);
index 18eac0119464219d17083c44abbe65d20461f0fd..ddb3f6541fac226baf636598b74c381cfaf24e0b 100644 (file)
@@ -474,22 +474,22 @@ constexpr int64_t exactDiv(int64_t a, int64_t b)
  */
 static inline int roundToInt(float x)
 {
-    return rintf(x);
+    return static_cast<int>(rintf(x));
 }
 //! Round double to int
 static inline int roundToInt(double x)
 {
-    return rint(x);
+    return static_cast<int>(rint(x));
 }
 //! Round float to int64_t
 static inline int64_t roundToInt64(float x)
 {
-    return rintf(x);
+    return static_cast<int>(rintf(x));
 }
 //! Round double to int64_t
 static inline int64_t roundToInt64(double x)
 {
-    return rint(x);
+    return static_cast<int>(rint(x));
 }
 
 } // namespace gmx
index 190053851e1ea807723e67900421ef934e1bffdc..c07693874398248f46b621802252b71d0220228e 100644 (file)
@@ -1265,7 +1265,7 @@ static real energyNoseHoover(const t_inputrec *ir, const t_state *state, const t
         const double *ivxi  = &state->nosehoover_vxi[i*nh];
         const double *iQinv = &(MassQ->Qinv[i*nh]);
 
-        int           nd    = ir->opts.nrdf[i];
+        int           nd    = static_cast<int>(ir->opts.nrdf[i]);
         real          reft  = std::max<real>(ir->opts.ref_t[i], 0);
         real          kT    = BOLTZ * reft;
 
@@ -1287,7 +1287,7 @@ static real energyNoseHoover(const t_inputrec *ir, const t_state *state, const t
                         }
                         else
                         {
-                            ndj = 1.0;
+                            ndj = 1;
                         }
                         energy += ndj*ixi[j]*kT;
                     }
index eb170467be6959f0ec7d1b79b5573741e1a31722..e7f805b370040432e590757adde5547d4fff7f50 100644 (file)
@@ -282,7 +282,7 @@ nbnxn_kernel_gpu_ref(const nbnxn_pairlist_t     *nbl,
                                 {
                                     r     = rsq*rinv;
                                     rt    = r*iconst->tabq_scale;
-                                    n0    = rt;
+                                    n0    = static_cast<int>(rt);
                                     eps   = rt - n0;
 
                                     fexcl = (1 - eps)*Ftab[n0] + eps*Ftab[n0+1];
index faf588b424554949f4b82968e4a99c792a2c337a..5395ca05958757775234ce0407b3fedffbbd08cc 100644 (file)
@@ -706,7 +706,7 @@ void pull_calc_coms(const t_commrec *cr,
     }
 
     pullAllReduce(cr, comm, pull->group.size()*3*DIM,
-                  static_cast<double *>(comm->comBuffer.data()[0]));
+                  static_cast<double *>(comm->comBuffer[0]));
 
     for (size_t g = 0; g < pull->group.size(); g++)
     {
index 52bbf6b81c9759326072e32c9af0d7255e14c4fc..a2a313eab1251d255b052c4b4a525de8596451a1 100644 (file)
@@ -379,7 +379,7 @@ parse_values_range(const SelectionParserValueList &values,
     /* Store the values */
     if (param->flags & SPAR_VARNUM)
     {
-        dataGuard.release();
+        (void)dataGuard.release();
         param->val.nr  = n;
         if (param->val.type == INT_VALUE)
         {
index 5c998412ee7c6778eda248d48a5fe989ff847c0b..ab0112b7fb9b8ae4d9e2199112f7bd8bf2e783c3 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/selection/position.h"
 #include "gromacs/selection/selectionenums.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
@@ -265,7 +266,7 @@ void SelectionTreeElement::mempoolReserve(int count)
             break;
 
         default:
-            GMX_THROW(gmx::InternalError("Memory pooling not implemented for requested type"));
+            gmx_incons("Memory pooling not implemented for requested type");
     }
 }
 
@@ -291,7 +292,7 @@ void SelectionTreeElement::mempoolRelease()
             break;
 
         default:
-            GMX_THROW(gmx::InternalError("Memory pooling not implemented for requested type"));
+            gmx_incons("Memory pooling not implemented for requested type");
     }
 }
 
index c9a5c6522005a0ac260ccff4862081b8742d9828..df588dbb6f836701ad702e9eedc969387177b8d4 100644 (file)
@@ -442,7 +442,7 @@ blend(float a, float b, bool sel)
 static inline std::int32_t
 cvtR2I(float a)
 {
-    return std::round(a);
+    return static_cast<std::int32_t>(std::round(a));
 };
 
 /*! \brief Truncate single precision floating point to integer.
@@ -457,7 +457,7 @@ cvtR2I(float a)
 static inline std::int32_t
 cvttR2I(float a)
 {
-    return std::trunc(a);
+    return static_cast<std::int32_t>(std::trunc(a));
 };
 
 /*! \brief Return integer.
@@ -844,7 +844,7 @@ blend(double a, double b, bool sel)
 static inline std::int32_t
 cvtR2I(double a)
 {
-    return std::round(a);
+    return static_cast<std::int32_t>(std::round(a));
 };
 
 /*! \brief Truncate single precision doubleing point to integer.
@@ -859,7 +859,7 @@ cvtR2I(double a)
 static inline std::int32_t
 cvttR2I(double a)
 {
-    return std::trunc(a);
+    return static_cast<std::int32_t>(std::trunc(a));
 };
 
 // We do not have a separate cvtI2R for double, since that would require
index e49007e506f3b9ba7735db51c1c24c82cac0c646..5609052df9bef4e44b112775202426f20529cf8b 100644 (file)
@@ -146,7 +146,7 @@ fillSingleCubicSplineTableData(const std::function<double(double)>   &function,
                                double                                 spacing,
                                std::vector<real>                     *yfghTableData)
 {
-    int  endIndex   = range.second / spacing + 2;
+    int  endIndex   = static_cast<int>(range.second / spacing + 2);
 
     yfghTableData->resize(4*endIndex);
 
@@ -227,7 +227,7 @@ fillSingleCubicSplineTableData(ArrayRef<const double>                 function,
                                double                                 spacing,
                                std::vector<real>                     *yfghTableData)
 {
-    int                 endIndex   = range.second / spacing + 2;
+    int                 endIndex   = static_cast<int>(range.second / spacing + 2);
 
     std::vector<double> tmpFunction(endIndex);
     std::vector<double> tmpDerivative(endIndex);
@@ -241,7 +241,7 @@ fillSingleCubicSplineTableData(ArrayRef<const double>                 function,
     {
         double x     = i * spacing;
         double xtab  = x / inputSpacing;
-        int    index = xtab;
+        int    index = static_cast<int>(xtab);
         double eps   = xtab - index;
 
         if (range.first > 0 && i == 0)
@@ -329,7 +329,7 @@ CubicSplineTable::CubicSplineTable(std::initializer_list<AnalyticalSplineTableIn
     double minQuotient = GMX_REAL_MAX;
 
     // loop over all functions to find smallest spacing
-    for (auto thisFuncInput : analyticalInputList)
+    for (const auto &thisFuncInput : analyticalInputList)
     {
         try
         {
@@ -368,7 +368,7 @@ CubicSplineTable::CubicSplineTable(std::initializer_list<AnalyticalSplineTableIn
     // combine them into a multiplexed table function.
     std::size_t funcIndex = 0;
 
-    for (auto thisFuncInput : analyticalInputList)
+    for (const auto &thisFuncInput : analyticalInputList)
     {
         try
         {
index 979c146704dd114ac7b563022fa48b60287a87b6..04b32c171ad3318e6bf51583eb79c32522c48763 100644 (file)
@@ -83,7 +83,7 @@ fillSingleQuadraticSplineTableData(const std::function<double(double)>   &functi
                                    std::vector<real>                     *functionTableData,
                                    std::vector<real>                     *derivativeTableData)
 {
-    std::size_t  endIndex   = range.second / spacing + 2;
+    std::size_t  endIndex   = static_cast<std::size_t>(range.second / spacing + 2);
 
     functionTableData->resize(endIndex);
     derivativeTableData->resize(endIndex);
@@ -162,7 +162,7 @@ fillSingleQuadraticSplineTableData(ArrayRef<const double>                 functi
                                    std::vector<real>                     *functionTableData,
                                    std::vector<real>                     *derivativeTableData)
 {
-    std::size_t  endIndex   = range.second / spacing + 2;
+    std::size_t  endIndex   = static_cast<std::size_t>(range.second / spacing + 2);
 
     functionTableData->resize(endIndex);
     derivativeTableData->resize(endIndex);
@@ -190,7 +190,7 @@ fillSingleQuadraticSplineTableData(ArrayRef<const double>                 functi
         {
             // Step 1: Interpolate the function value at x from input table.
             double inputXTab  = x / inputSpacing;
-            int    inputIndex = inputXTab;
+            int    inputIndex = static_cast<std::size_t>(inputXTab);
             double inputEps   = inputXTab - inputIndex;
 
             // Linear interpolation of input derivative and third derivative
@@ -288,7 +288,7 @@ QuadraticSplineTable::QuadraticSplineTable(std::initializer_list<AnalyticalSplin
     double minQuotient = GMX_REAL_MAX;
 
     // loop over all functions to find smallest spacing
-    for (auto thisFuncInput : analyticalInputList)
+    for (const auto &thisFuncInput : analyticalInputList)
     {
         try
         {
@@ -324,7 +324,7 @@ QuadraticSplineTable::QuadraticSplineTable(std::initializer_list<AnalyticalSplin
     // combine them into a multiplexed table function.
     std::size_t funcIndex = 0;
 
-    for (auto thisFuncInput : analyticalInputList)
+    for (const auto &thisFuncInput : analyticalInputList)
     {
         try
         {
index 9a21fe2e03599c61c6f14e35334d72229f63b2ac..e78b198c21d5a5c6a305a6a6c03a667ab1da1179 100644 (file)
@@ -114,8 +114,8 @@ throwUnlessDerivativeIsConsistentWithFunction(ArrayRef<const double>        func
                                               double                        inputSpacing,
                                               const std::pair<real, real>  &range)
 {
-    std::size_t     firstIndex   = range.first / inputSpacing;
-    std::size_t     lastIndex    = range.second / inputSpacing;
+    std::size_t     firstIndex   = static_cast<std::size_t>(range.first / inputSpacing);
+    std::size_t     lastIndex    = static_cast<std::size_t>(range.second / inputSpacing);
     bool            isConsistent = true;
     std::size_t     minFail      = lastIndex;
     std::size_t     maxFail      = firstIndex;
@@ -214,8 +214,8 @@ findSmallestQuotientOfFunctionAndSecondDerivative(ArrayRef<const double>
                                                   const std::pair<real, real>   &range)
 {
 
-    std::size_t  firstIndex  = range.first  / inputSpacing;
-    std::size_t  lastIndex   = range.second / inputSpacing;
+    std::size_t  firstIndex  = static_cast<std::size_t>(range.first  / inputSpacing);
+    std::size_t  lastIndex   = static_cast<std::size_t>(range.second / inputSpacing);
     double       minQuotient = GMX_REAL_MAX;
 
     for (std::size_t i = firstIndex + 1; (i + 1) < lastIndex; i++)
@@ -292,8 +292,8 @@ findSmallestQuotientOfFunctionAndThirdDerivative(ArrayRef<const double>        f
                                                  const std::pair<real, real>   &range)
 {
 
-    std::size_t  firstIndex  = range.first  / inputSpacing;
-    std::size_t  lastIndex   = range.second / inputSpacing;
+    std::size_t  firstIndex  = static_cast<std::size_t>(range.first  / inputSpacing);
+    std::size_t  lastIndex   = static_cast<std::size_t>(range.second / inputSpacing);
     double       minQuotient = GMX_REAL_MAX;
 
     for (std::size_t i = firstIndex + 2; (i + 2) < lastIndex; i++)
index 5761699e8b610def0697a5b1813e3eef75264a31..a2512322daf012f952fa9d45fa8fceaddd711177 100644 (file)
@@ -43,6 +43,7 @@
 #include <cstdio>
 #include <cstring>
 
+#include "gromacs/math/functions.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/topology/residuetypes.h"
 #include "gromacs/utility/cstringutil.h"
@@ -421,7 +422,7 @@ int gmx_atomprop_atomnumber(gmx_atomprop_t aps, const char *elem)
     {
         if (gmx_strcasecmp(ap->prop[epropElement].atomnm[i], elem) == 0)
         {
-            return std::round(ap->prop[epropElement].value[i]);
+            return gmx::roundToInt(ap->prop[epropElement].value[i]);
         }
     }
     return -1;
index f7323a8d87bb627fe393f4fe7c6ad466f7f9bdf5..3341d040964ed1186ff76d17edaeaec46280ddd6 100644 (file)
@@ -203,7 +203,7 @@ TrajectoryAnalysisRunnerCommon::Impl::initFirstFrame()
         return;
     }
     time_unit_t time_unit
-        = static_cast<time_unit_t>(settings_.timeUnit() + 1); // NOLINT(misc-misplaced-widening-cast)
+        = static_cast<time_unit_t>(settings_.timeUnit() + 1); // NOLINT(bugprone-misplaced-widening-cast)
     output_env_init(&oenv_, getProgramContext(), time_unit, FALSE, exvgNONE, 0);
 
     int frflags = settings_.frflags();
index 604081299b77af93fb423074e354613ff6a7bd03..1b3fe93f82f068b81f8a87809c7ef1b5544deb38 100644 (file)
@@ -147,7 +147,7 @@ inline static void bitmask_init_low_bits(gmx_bitmask_t* m, int b)
 {
     memset(m->data(), 255, b/64*8);
     (*m)[b/64] = (static_cast<uint64_t>(1) << (b%64)) - 1;
-    memset(&(m->data())[b/64+1], 0, (BITMASK_ALEN-b/64-1)*8);
+    memset(&(*m)[b/64+1], 0, (BITMASK_ALEN-b/64-1)*8);
 }
 
 inline static bool bitmask_is_set(gmx_bitmask_t m, int b)
index 8ea8138b54d5633c808a8e9604a5dbf99bb9bc1f..a15b7bc4e98a769dc26df03e363ae86040feef05 100644 (file)
@@ -660,36 +660,33 @@ int gmx_file_rename(const char *oldname, const char *newname)
 
 int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_empty)
 {
-/* the full copy buffer size: */
-#define FILECOPY_BUFSIZE (1<<16)
-    FILE *in  = nullptr;
-    FILE *out = nullptr;
-    char *buf;
-
-    snew(buf, FILECOPY_BUFSIZE);
-
-    in = fopen(oldname, "rb");
+    gmx::FilePtr in(fopen(oldname, "rb"));
     if (!in)
     {
-        goto error;
+        return 1;
     }
 
     /* If we don't copy when empty, we postpone opening the file
        until we're actually ready to write. */
+    gmx::FilePtr out;
     if (copy_if_empty)
     {
-        out = fopen(newname, "wb");
+        out.reset(fopen(newname, "wb"));
         if (!out)
         {
-            goto error;
+            return 1;
         }
     }
 
-    while (!feof(in))
+    /* the full copy buffer size: */
+    constexpr int     FILECOPY_BUFSIZE = 1<<16;
+    std::vector<char> buf(FILECOPY_BUFSIZE);
+
+    while (!feof(in.get()))
     {
         size_t nread;
 
-        nread = fread(buf, sizeof(char), FILECOPY_BUFSIZE, in);
+        nread = fread(buf.data(), sizeof(char), FILECOPY_BUFSIZE, in.get());
         if (nread > 0)
         {
             size_t ret;
@@ -697,39 +694,24 @@ int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_emp
             {
                 /* so this is where we open when copy_if_empty is false:
                    here we know we read something. */
-                out = fopen(newname, "wb");
+                out.reset(fopen(newname, "wb"));
                 if (!out)
                 {
-                    goto error;
+                    return 1;
                 }
             }
-            ret = fwrite(buf, sizeof(char), nread, out);
+            ret = fwrite(buf.data(), sizeof(char), nread, out.get());
             if (ret != nread)
             {
-                goto error;
+                return 1;
             }
         }
-        if (ferror(in))
+        if (ferror(in.get()))
         {
-            goto error;
+            return 1;
         }
     }
-    sfree(buf);
-    fclose(in);
-    fclose(out);
     return 0;
-error:
-    sfree(buf);
-    if (in)
-    {
-        fclose(in);
-    }
-    if (out)
-    {
-        fclose(out);
-    }
-    return 1;
-#undef FILECOPY_BUFSIZE
 }
 
 
index f42a3f16d9c709c254fa83e146d91bcfd2e795b9..70196a130e02840ccccc80629179be98fb3e32a1 100644 (file)
@@ -126,7 +126,7 @@ std::string stripString(const std::string &str)
     {
         ++start;
     }
-    while (start != end && std::isspace(*(end - 1)))
+    while (start != end && (std::isspace(*(end - 1)) != 0))
     {
         --end;
     }
index 5ee7fb5b10bf57a7b5ffd60bdad1341e5cb2f9b3..c171ae573e87d0334a5b9cbebc91ad949a273980 100644 (file)
@@ -230,7 +230,7 @@ TEST_P(MdrunRerunTest, WithinTolerances)
                                                 "no", "no");
 
     // bd is much less reproducible in a rerun than the other integrators
-    double           toleranceScaleFactor = (integrator == "bd") ? 2 : 1;
+    const int        toleranceScaleFactor = (integrator == "bd") ? 2 : 1;
     EnergyTolerances energiesToMatch
     {{
          {
index 8990bd81f74249e8077f3bb9deaabdab808941b9..c4a2cce9ecdc76e0c8dfc33dd1d06540d24e3adc 100644 (file)
@@ -515,7 +515,8 @@ static inline FloatingPointTolerance defaultRealTolerance()
 static inline FloatingPointTolerance defaultFloatTolerance()
 {
     return relativeToleranceAsPrecisionDependentUlp
-               (1.0, detail::g_defaultUlpTolerance, detail::g_defaultUlpTolerance * (GMX_FLOAT_EPS / GMX_DOUBLE_EPS));
+               (1.0, detail::g_defaultUlpTolerance,
+               static_cast<uint64_t>(detail::g_defaultUlpTolerance * (GMX_FLOAT_EPS / GMX_DOUBLE_EPS)));
 }
 
 /*! \name Assertions for floating-point comparison