clang-tidy: 4 readability checks
authorRoland Schulz <roland.schulz@intel.com>
Mon, 25 Jun 2018 08:05:13 +0000 (01:05 -0700)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 28 Jun 2018 06:53:05 +0000 (08:53 +0200)
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-simplify-boolean-expr
readability-container-size-empty

Change in src/gromacs/utility/exceptions.cpp manual.

Change-Id: I25580faa80f2d5b81a1e754ae7486e954b490dc8

22 files changed:
src/gromacs/CMakeLists.txt
src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/awh/biasparams.cpp
src/gromacs/awh/biasstate.cpp
src/gromacs/awh/coordstate.cpp
src/gromacs/commandline/cmdlineprogramcontext.cpp
src/gromacs/domdec/collect.cpp
src/gromacs/domdec/distribute.cpp
src/gromacs/essentialdynamics/edsam.cpp
src/gromacs/fileio/checkpoint.cpp
src/gromacs/gmxana/gmx_awh.cpp
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/main.cpp
src/gromacs/mdlib/vsite.cpp
src/gromacs/mdrun/md.cpp
src/gromacs/options/basicoptions.cpp
src/gromacs/selection/params.cpp
src/gromacs/selection/poscalc.cpp
src/gromacs/selection/selectionoption.cpp
src/gromacs/taskassignment/decidegpuusage.cpp
src/gromacs/utility/exceptions.cpp
src/gromacs/utility/path.cpp

index 6ce2470b84d98140a604f82ca23630cddd39c6b6..ed40929df231b6414dce0c1dc5abb80841d19a6b 100644 (file)
@@ -279,9 +279,8 @@ if (GMX_CLANG_TIDY)
    set_target_properties(libgromacs PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--checks=\
        -clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-core.NullDereference,\
        bugprone-*,misc-*,readability-*,performance-*,mpi-*,-bugprone-integer-division,\
-       -readability-redundant-smartptr-get,-readability-redundant-string-cstr,-readability-simplify-boolean-expr,\
        -misc-misplaced-widening-cast,-readability-named-parameter,-performance-noexcept-move-constructor,\
-       -readability-misleading-indentation,-readability-container-size-empty,-misc-suspicious-string-compare,\
+       -readability-misleading-indentation,-misc-suspicious-string-compare,\
        -readability-redundant-control-flow,-performance-unnecessary-value-param,\
        -readability-static-definition-in-anonymous-namespace,-misc-suspicious-missing-comma,\
        -readability-redundant-member-init,-misc-misplaced-const,\
index f61b34e366d86f9971b04d98aa8ef87e47804c9d..c80a5bba386379618be33126efa255967680ebe8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -346,7 +346,7 @@ AbstractPlotModule::dataStarted(AbstractAnalysisData * /* data */)
             output_env_init(&oenv, getProgramContext(), time_unit, FALSE, xvg_format, 0);
             const unique_cptr<gmx_output_env_t, output_env_done> oenvGuard(oenv);
             impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(),
-                                  impl_->xlabel_.c_str(), impl_->ylabel_.c_str(),
+                                  impl_->xlabel_, impl_->ylabel_,
                                   oenv);
             const SelectionCollection *selections
                 = impl_->settings_.selectionCollection();
index d34cb9550877ae5f8664662392f8cb05caeeb6d0..c6608126607e98c61fa51a42531eca6596d51bd7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -175,7 +175,7 @@ double gaussianGeometryFactor(gmx::ArrayRef<const double> xArray)
         xScalar *= x;
     }
 
-    GMX_ASSERT(xArray.size() > 0, "We should have a non-empty input array");
+    GMX_ASSERT(!xArray.empty(), "We should have a non-empty input array");
     xScalar = std::pow(xScalar, 1.0/xArray.size());
 
     /* Look up zeta(x) */
index b689e72dd1c6293795635ef81d439162fa161ee8..228bb6b768eb06bc4f1561f85c28606437f46729 100644 (file)
@@ -1478,7 +1478,7 @@ static void readUserPmfAndTargetDistribution(const std::vector<DimParams> &dimPa
                      filename.c_str());
     gmx::TextLineWrapper wrapper;
     wrapper.settings().setLineLength(c_linewidth);
-    correctFormatMessage = wrapper.wrapToString(correctFormatMessage).c_str();
+    correctFormatMessage = wrapper.wrapToString(correctFormatMessage);
 
     double  **data;
     int       numColumns;
index 7d719f48b65b30c99142d3a321280f781f8c5628..ef431153c2a6b689fd0054d9a79b53d6287e3cf1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -102,7 +102,7 @@ int getSampleFromDistribution(ArrayRef<const double> distr,
     gmx::ThreeFry2x64<0>               rng(seed, gmx::RandomDomain::AwhBiasing);
     gmx::UniformRealDistribution<real> uniformRealDistr;
 
-    GMX_RELEASE_ASSERT(distr.size() > 0, "We need a non-zero length distribution to sample from");
+    GMX_RELEASE_ASSERT(!distr.empty(), "We need a non-zero length distribution to sample from");
 
     /* Generate the cumulative probability distribution function */
     std::vector<double> cumulativeDistribution(distr.size());
index dc15cd2df794c62a54e233beb15f78305302e9c1..d6954c1bb99fed4f027b17538581b31b44a62ae7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -187,11 +187,7 @@ bool isAcceptableLibraryPath(const std::string &path)
 bool isAcceptableLibraryPathPrefix(const std::string &path)
 {
     std::string testPath = Path::join(path, DATA_INSTALL_DIR, "top");
-    if (isAcceptableLibraryPath(testPath))
-    {
-        return true;
-    }
-    return false;
+    return isAcceptableLibraryPath(testPath);
 }
 
 /*! \brief
index 4f9415a9f12fa9aaf2ef00bef46c6140153863da..d5564e18c89ab8ca96e0f26e7f36ef602ace7e6b 100644 (file)
@@ -160,7 +160,7 @@ static void dd_collect_vec_sendrecv(gmx_domdec_t                  *dd,
     }
     else
     {
-        AtomDistribution &ma = *dd->ma.get();
+        AtomDistribution &ma = *dd->ma;
 
         /* Copy the master coordinates to the global array */
         const t_block &cgs_gl    = dd->comm->cgs_gl;
index 4d9984f15b5d7ccf9f67dc36f4af782e2c5f3a7b..ff1fc6520cf98396c13351344a17c37be2f50b9a 100644 (file)
@@ -125,7 +125,7 @@ static void distributeVecScatterv(gmx_domdec_t                   *dd,
 
     if (DDMASTER(dd))
     {
-        AtomDistribution &ma = *dd->ma.get();
+        AtomDistribution &ma = *dd->ma;
 
         get_commbuffer_counts(&ma, &sendCounts, &displacements);
 
@@ -283,7 +283,7 @@ getAtomGroupDistribution(FILE *fplog,
                          const t_block *cgs, rvec pos[],
                          gmx_domdec_t *dd)
 {
-    AtomDistribution &ma = *dd->ma.get();
+    AtomDistribution &ma = *dd->ma;
 
     /* Clear the count */
     for (int rank = 0; rank < dd->nnodes; rank++)
index e5513e9b9f298c60be16a7e8f872d04f7554256a..280ee16ba4d9301215e7034a95d1edb9b6c474e8 100644 (file)
@@ -1126,7 +1126,7 @@ static gmx_edsam_t ed_open(
         snew(ed->edpar, 1);
 
         // If we start from a checkpoint file, we already have an edsamHistory struct
-        if (oh->edsamHistory.get() == nullptr)
+        if (oh->edsamHistory == nullptr)
         {
             oh->edsamHistory = std::unique_ptr<edsamhistory_t>(new edsamhistory_t {});
         }
index 26dff8a6c57288c4d691121492da7862322e84a6..eda2ab57b139b4010a2793351fd1947fc68f426a 100644 (file)
@@ -1884,7 +1884,7 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
     }
 
     int flags_awhh = 0;
-    if (state->awhHistory != nullptr && state->awhHistory->bias.size() > 0)
+    if (state->awhHistory != nullptr && !state->awhHistory->bias.empty())
     {
         flags_awhh |= ( (1 << eawhhIN_INITIAL) |
                         (1 << eawhhEQUILIBRATEHISTOGRAM) |
index 60138e6109e00f4344ec783facfdcef574afa800..9d1317cd38b976aa89ba8bd7a55b6388c4308e59 100644 (file)
@@ -195,7 +195,7 @@ struct BiasOutputSetup
     {
         GMX_RELEASE_ASSERT(awhOutputFile_ != nullptr, "awhOutputFile() called without initialized AWH output file");
 
-        return *awhOutputFile_.get();
+        return *awhOutputFile_;
     }
 
     //! Return the a pointer to the friction output file data, can return nullptr
index 569ff867f7237dc719afd861ab586d169a7f9455..9aab4b2dfef2ed1dc6e36c92418b9737fcd3b106 100644 (file)
@@ -1460,7 +1460,7 @@ static bondedtable_t *make_bonded_tables(FILE *fplog,
                 bool        madeTable     = false;
                 for (size_t j = 0; j < tabbfnm.size() && !madeTable; ++j)
                 {
-                    if (gmx::endsWith(tabbfnm[j].c_str(), patternToFind))
+                    if (gmx::endsWith(tabbfnm[j], patternToFind))
                     {
                         // Finally read the table from the file found
                         tab[i]    = make_bonded_table(fplog, tabbfnm[j].c_str(), NRAL(ftype1)-2);
index 503dad983e35b3cae1177ee4157e876604c0a697..830856c6891eef14febc570abe55f27293bb9180 100644 (file)
@@ -253,7 +253,7 @@ gmx_multisim_t *init_multisystem(MPI_Comm                         comm,
         return nullptr;
     }
 
-    if (!GMX_LIB_MPI && multidirs.size() >= 1)
+    if (!GMX_LIB_MPI && !multidirs.empty())
     {
         gmx_fatal(FARGS, "mdrun -multidir is only supported when GROMACS has been "
                   "configured with a proper external MPI library.");
index 3fc74f961ba854061edfbfb3d529a91ba93ab88d..711a487fa2d0fb278d036decff1cc91d0dbe0521 100644 (file)
@@ -2530,12 +2530,12 @@ void split_vsites_over_threads(const t_ilist   *ilist,
                 for (int t = 0; t < vsite->nthreads; t++)
                 {
                     /* Do we write to the force buffer of task t? */
-                    if (idTask->atomIndex[t].atom.size() > 0)
+                    if (!idTask->atomIndex[t].atom.empty())
                     {
                         idTask->spreadTask.push_back(t);
                     }
                     /* Does task t write to our force buffer? */
-                    if (vsite->tData[t]->idTask.atomIndex[thread].atom.size() > 0)
+                    if (!vsite->tData[t]->idTask.atomIndex[thread].atom.empty())
                     {
                         idTask->reduceTask.push_back(t);
                     }
index a5cf111fe40a08c9eee7e359d2de1da02db148b4..82e8550e3e2b93f53318f405c58097bbeca3b646 100644 (file)
@@ -518,7 +518,7 @@ void gmx::Integrator::do_md()
             {
                 restore_energyhistory_from_state(mdebin, observablesHistory->energyHistory.get());
             }
-            else if (observablesHistory->energyHistory.get() != nullptr)
+            else if (observablesHistory->energyHistory != nullptr)
             {
                 /* We might have read an energy history from checkpoint.
                  * As we are not appending, we want to restart the statistics.
@@ -527,7 +527,7 @@ void gmx::Integrator::do_md()
                 observablesHistory->energyHistory = {};
             }
         }
-        if (observablesHistory->energyHistory.get() == nullptr)
+        if (observablesHistory->energyHistory == nullptr)
         {
             observablesHistory->energyHistory = std::unique_ptr<energyhistory_t>(new energyhistory_t {});
         }
index 57e691f74f0dfb08aebb7eed27a937d5d569c241..17f6af248e8cc19196d8e4a5a0d2f66ac5acc90e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -506,7 +506,7 @@ void StringOptionStorage::initConverter(ConverterType * /*converter*/)
 
 std::string StringOptionStorage::processValue(const std::string &value) const
 {
-    if (allowed_.size() > 0)
+    if (!allowed_.empty())
     {
         return *findEnumValue(this->allowed_, value);
     }
index 4e69009cbe1d752031c44e2231af8f14ebe7385b..d33485f90e01579ff78979e48711c9fd4a28c82b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -960,7 +960,7 @@ parse_values_bool(const std::string &name,
         bSetNo = true;
     }
 
-    *param->val.u.b = bSetNo ? false : true;
+    *param->val.u.b = !bSetNo;
 }
 
 /*! \brief
index 0fe921501c4a081a1e1367688180a7bfa983e3cc..28f8c85118d2afd11cb21e17c7ee9263bdcff0e4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -1218,7 +1218,7 @@ gmx_ana_poscalc_update(gmx_ana_poscalc_t *pc, gmx_ana_pos_t *p,
 {
     int  i, bi, bj;
 
-    if (pc->bEval == true && !(pc->flags & POS_MASKONLY))
+    if (pc->bEval && !(pc->flags & POS_MASKONLY))
     {
         return;
     }
index b9ccda569b58326bbe9e62b8ae018a99a0a8c9b0..2635cbe78a856c4d7d0c8389381b3b0f75321d31 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -132,7 +132,7 @@ void SelectionOptionStorage::convertValue(const Variant &value)
 
 void SelectionOptionStorage::processSetValues(ValueList *values)
 {
-    if (values->size() == 0)
+    if (values->empty())
     {
         manager_.requestOptionDelayedParsing(this);
     }
index 1e397586a27addbf15ff57d6325cf77baebdcb83..94e7274552c35785379e00d54fad57c1d0a70736 100644 (file)
@@ -217,7 +217,7 @@ decideWhetherToUseGpusForPmeWithThreadMpi(const bool              useGpuForNonbo
     {
         // PME can run well on a GPU shared with NB, and we permit
         // mdrun to default to try that.
-        return gpuIdsToUse.size() >= 1;
+        return !gpuIdsToUse.empty();
     }
 
     if (numRanksPerSimulation < 1)
index a90da61fbf7da22edfd0c40fed635c3a47c07470..0dd967c908c19e1227e5dc23e0ab6c31e3ec074a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -392,7 +392,7 @@ class MessageWriterString : public IMessageWriter
         //! Post-processes the output string to not end in a line feed.
         void removeTerminatingLineFeed()
         {
-            if (result_.size() > 0U)
+            if (!result_.empty())
             {
                 result_.erase(result_.size() - 1);
             }
index 1bf323f4c28f9349055f4477e520e6cbe54c33b8..bdb2e5e9406079cb38a47769ba530827d7e1eaba 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -117,14 +117,10 @@ bool Path::containsDirectory(const std::string &path)
  */
 bool Path::isAbsolute(const char *path)
 {
-    if (isDirSeparator(path[0]))
-    {
-        return true;
-    }
 #if GMX_NATIVE_WINDOWS
     return path[0] != '\0' && path[1] == ':' && isDirSeparator(path[2]);
 #else
-    return false;
+    return isDirSeparator(path[0]);
 #endif
 }