]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix CppCheck complaints
authorDaniel Arndt <arndtd@ornl.gov>
Thu, 4 Jul 2024 15:35:52 +0000 (11:35 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Thu, 4 Jul 2024 16:48:48 +0000 (12:48 -0400)
26 files changed:
include/deal.II/algorithms/any_data.h
include/deal.II/algorithms/newton.templates.h
include/deal.II/algorithms/timestep_control.h
include/deal.II/base/parallel.h
include/deal.II/base/table_handler.h
include/deal.II/base/thread_management.h
include/deal.II/distributed/cell_data_transfer.h
include/deal.II/distributed/cell_data_transfer.templates.h
include/deal.II/fe/fe_system.h
include/deal.II/grid/tria.h
include/deal.II/lac/sparsity_pattern.h
source/algorithms/timestep_control.cc
source/base/convergence_table.cc
source/base/exceptions.cc
source/base/mpi_compute_index_owner_internal.cc
source/base/mu_parser_internal.cc
source/base/parallel.cc
source/base/parameter_acceptor.cc
source/base/parameter_handler.cc
source/base/polynomials_barycentric.cc
source/base/quadrature_lib.cc
source/base/table_handler.cc
source/base/utilities.cc
source/dofs/dof_handler.cc
source/dofs/dof_tools.cc
source/fe/fe_dgq.cc

index 6ed42506337716e35805140de9dba4ae98c95c67..c23fa925e88126f16355ef101b409e22a449965c 100644 (file)
@@ -230,7 +230,7 @@ inline type
 AnyData::entry(const unsigned int i)
 {
   AssertIndexRange(i, size());
-  type *p = std::any_cast<type>(&data[i]);
+  const type *p = std::any_cast<type>(&data[i]);
   Assert(p != nullptr,
          ExcTypeMismatch(typeid(type).name(), data[i].type().name()));
   return *p;
@@ -349,7 +349,7 @@ inline type
 AnyData::entry(const std::string &n)
 {
   const unsigned int i = find(n);
-  type              *p = std::any_cast<type>(&data[i]);
+  const type        *p = std::any_cast<type>(&data[i]);
   Assert(p != 0, ExcTypeMismatch(typeid(type).name(), data[i].type().name()));
   return *p;
 }
index 55c81f0a69f896c1fc424ba328c824098e726208..6feed39cc7f3f5f9868e1b16071c787c1270e889 100644 (file)
@@ -156,7 +156,7 @@ namespace Algorithms
           {
             (*inverse_derivative)(out2, src2);
           }
-        catch (SolverControl::NoConvergence &e)
+        catch (const SolverControl::NoConvergence &e)
           {
             deallog << "Inner iteration failed after " << e.last_step
                     << " steps with residual " << e.last_residual << std::endl;
index a9f71f1fcaeb114147295c9a4895f83a6299ff47..72aed99d98fcdb7eec628ef7c12141fa753bfc2f 100644 (file)
@@ -84,7 +84,7 @@ namespace Algorithms
      * the parameters just read.
      */
     void
-    parse_parameters(ParameterHandler &param);
+    parse_parameters(const ParameterHandler &param);
 
     /**
      * Return the left end of the time interval.
index 1495f621056c90c18149a1faec946f642d5dcd45..8c20c925831827b4ed6c4bfc860f5008edfb4925 100644 (file)
@@ -674,7 +674,8 @@ namespace parallel
        * again.
        */
       void
-      release_one_partitioner(std::shared_ptr<tbb::affinity_partitioner> &p);
+      release_one_partitioner(
+        const std::shared_ptr<tbb::affinity_partitioner> &p);
 
     private:
       /**
index 5a7d502b3b85e66fa6783c384b0af1fc8c9b71e2..506e20afa61a333d8a9c2c21ebd9a49d9426291a 100644 (file)
@@ -961,7 +961,7 @@ TableHandler::add_value(const std::string &key, const T value)
       while (columns[key].entries.size() + 1 < max_col_length)
         {
           columns[key].entries.push_back(internal::TableEntry(T()));
-          internal::TableEntry &entry = columns[key].entries.back();
+          const internal::TableEntry &entry = columns[key].entries.back();
           entry.cache_string(columns[key].scientific, columns[key].precision);
           columns[key].max_length =
             std::max(columns[key].max_length,
@@ -972,7 +972,7 @@ TableHandler::add_value(const std::string &key, const T value)
 
   // now push the value given to this function
   columns[key].entries.push_back(internal::TableEntry(value));
-  internal::TableEntry &entry = columns[key].entries.back();
+  const internal::TableEntry &entry = columns[key].entries.back();
   entry.cache_string(columns[key].scientific, columns[key].precision);
   columns[key].max_length =
     std::max(columns[key].max_length,
index b69d4611a3e4151f1ef45c666323e8c3735b4340..f130ef0c95e700f9d3b1de8e9de069b1e4ca31bb 100644 (file)
@@ -393,7 +393,7 @@ namespace Threads
     struct maybe_make_ref
     {
       static T
-      act(T &t)
+      act(const T &t)
       {
         return t;
       }
@@ -1432,7 +1432,7 @@ namespace Threads
     void
     join_all() const
     {
-      for (auto &t : tasks)
+      for (const auto &t : tasks)
         t.join();
     }
 
index 861497932825a140f3829dbe8a08aadff0184d31..8b2e1bef2ffca0c8e4dc0d61e04469d8bc5f7526 100644 (file)
@@ -302,8 +302,8 @@ namespace parallel
           cell_iterator &cell,
         const CellStatus status,
         const boost::iterator_range<std::vector<char>::const_iterator>
-                                  &data_range,
-        std::vector<VectorType *> &all_out);
+                                        &data_range,
+        const std::vector<VectorType *> &all_out);
     };
   } // namespace distributed
 } // namespace parallel
index ebbb1a856ba57f60acbe1fcdb81fd3764e4b19fb..7ceffefe9720b88e61713aa159ea9410d281e661 100644 (file)
@@ -308,8 +308,8 @@ namespace parallel
         cell_iterator &cell,
       const CellStatus status,
       const boost::iterator_range<std::vector<char>::const_iterator>
-                                &data_range,
-      std::vector<VectorType *> &all_out)
+                                      &data_range,
+      const std::vector<VectorType *> &all_out)
     {
       std::vector<value_type> cell_data;
 
index 68c1c724db0a7acae82d0ff71d8698cf64760395..cc8ffe3716dc6cb3d4bfa4bcee3ecc2bc58f426c 100644 (file)
@@ -572,11 +572,10 @@ public:
    */
   FESystem(FESystem<dim, spacedim> &&other_fe_system) noexcept
     : FiniteElement<dim, spacedim>(std::move(other_fe_system))
-  {
-    base_elements = std::move(other_fe_system.base_elements);
-    generalized_support_points_index_table =
-      std::move(other_fe_system.generalized_support_points_index_table);
-  }
+    , base_elements(std::move(other_fe_system.base_elements))
+    , generalized_support_points_index_table(
+        std::move(other_fe_system.generalized_support_points_index_table))
+  {}
 
   /**
    * Destructor.
index d92c8ff735049977bb9c424755d6e5d7b76ebb2e..7973e4667f4727f70f00e1dcb71cf78b99647cb2 100644 (file)
@@ -4724,7 +4724,7 @@ void Triangulation<dim, spacedim>::load(Archive &ar, const unsigned int)
   // they are easy enough to rebuild upon re-loading data. do
   // this here. don't forget to first resize the fields appropriately
   {
-    for (auto &level : levels)
+    for (const auto &level : levels)
       {
         level->active_cell_indices.resize(level->refine_flags.size());
         level->global_active_cell_indices.resize(level->refine_flags.size());
index 842cce0b5dbe4ddffbcb97f78ab209d0d9473380..7b0e93d358ed797172cda3c68525f45fb8da9cda 100644 (file)
@@ -1408,14 +1408,15 @@ SparsityPattern::operator==(const SparsityPattern &sp2) const
     return false;
 
   if (rows > 0)
-    for (size_type i = 0; i < rows + 1; ++i)
-      if (rowstart[i] != sp2.rowstart[i])
-        return false;
+    {
+      for (size_type i = 0; i < rows + 1; ++i)
+        if (rowstart[i] != sp2.rowstart[i])
+          return false;
 
-  if (rows > 0)
-    for (size_type i = 0; i < rowstart[rows]; ++i)
-      if (colnums[i] != sp2.colnums[i])
-        return false;
+      for (size_type i = 0; i < rowstart[rows]; ++i)
+        if (colnums[i] != sp2.colnums[i])
+          return false;
+    }
 
   return true;
 }
index 8f7c66cb1f560429f34ddb5c72bdf4fbed30d84b..9425cda8bc972d7d1e183ea298d008df946c6a65 100644 (file)
@@ -60,7 +60,7 @@ namespace Algorithms
 
 
   void
-  TimestepControl::parse_parameters(ParameterHandler &param)
+  TimestepControl::parse_parameters(const ParameterHandler &param)
   {
     start(param.get_double("Start"));
     start_step(param.get_double("First step"));
index 24387162c33bb24e2513b2c62a38d6db593dbac6..5647cc68ebf69accd1b0cf0e591c618b4ae1ba35 100644 (file)
@@ -36,8 +36,9 @@ ConvergenceTable::evaluate_convergence_rates(
   // the top that don't yet exist
   set_auto_fill_mode(false);
 
-  std::vector<internal::TableEntry> &entries = columns[data_column_key].entries;
-  std::vector<internal::TableEntry> &ref_entries =
+  const std::vector<internal::TableEntry> &entries =
+    columns[data_column_key].entries;
+  const std::vector<internal::TableEntry> &ref_entries =
     columns[reference_column_key].entries;
   std::string rate_key = data_column_key + "...";
 
@@ -132,8 +133,9 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
   // the top that don't yet exist
   set_auto_fill_mode(false);
 
-  std::vector<internal::TableEntry> &entries = columns[data_column_key].entries;
-  std::string                        rate_key = data_column_key + "...";
+  const std::vector<internal::TableEntry> &entries =
+    columns[data_column_key].entries;
+  std::string rate_key = data_column_key + "...";
 
   const unsigned int n = entries.size();
 
index 50cd791f1ddd8158b618389a1c77b849cc527e01..9b32898f1408e3f56e621fd271a3a3983e8273b0 100644 (file)
@@ -285,7 +285,7 @@ ExceptionBase::print_stack_trace(std::ostream &out) const
       std::string functionname =
         stacktrace_entry.substr(pos_start + 1, pos_end - pos_start - 1);
 
-      stacktrace_entry = stacktrace_entry.substr(0, pos_start);
+      stacktrace_entry.resize(pos_start);
       stacktrace_entry += ": ";
 
       // demangle, and if successful replace old mangled string by
index 651aebf7f902727be432ad17574e2c4bad1272ba..c7825de9901a1cb160920c4be75c00d3dd994120 100644 (file)
@@ -114,10 +114,8 @@ namespace Utilities
             }
           else
             {
-              if (data_map.find(index) == data_map.end())
-                data_map[index] = invalid_index_value;
-
-              return data_map[index];
+              return data_map.try_emplace(index, invalid_index_value)
+                .first->second;
             }
         }
 
index f8d32dae9b3aa2c85acc7680273f6a65278736a9..739a56d01e81ba0e9fd89c76fdccc0ad77e2b7fb 100644 (file)
@@ -167,10 +167,9 @@ namespace internal
       // which is initialized with the seed itself
       static std::map<double, std::mt19937> rng_map;
 
-      if (rng_map.find(seed) == rng_map.end())
-        rng_map[seed] = std::mt19937(static_cast<unsigned int>(seed));
-
-      return uniform_distribution(rng_map[seed]);
+      return uniform_distribution(
+        rng_map.try_emplace(seed, std::mt19937(static_cast<unsigned int>(seed)))
+          .first->second);
     }
 
 
index d426446b534dd503da3db3b720ed3af0ce2786e4..7ccafffb2cfd6df029d5aac996defa819eae344f 100644 (file)
@@ -85,7 +85,7 @@ namespace parallel
 
     void
     TBBPartitioner::release_one_partitioner(
-      std::shared_ptr<tbb::affinity_partitioner> &p)
+      const std::shared_ptr<tbb::affinity_partitioner> &p)
     {
       if (p.get() == my_partitioner.get())
         {
index ebaf9252396cd6073f25ca1aca74d5638a446815..7610532d8ee1b623703f8850f5c674c58990f458 100644 (file)
@@ -59,12 +59,7 @@ ParameterAcceptor::ParameterAcceptor(const std::string &name)
 ParameterAcceptor::~ParameterAcceptor()
 {
   std::lock_guard<std::mutex> l(class_list_mutex);
-  // Notice that it is possible that the class is no longer in the static list.
-  // This happens when the clear() method has been called. We must guard that
-  // this is not the case, and therefore we only remove ourselves from the list
-  // if we are actually there.
-  if (class_list.find(this) != class_list.end())
-    class_list.erase(this);
+  class_list.erase(this);
 }
 
 
@@ -198,7 +193,7 @@ ParameterAcceptor::get_section_path() const
            acceptor_it != class_list.rend();
            ++acceptor_it)
         {
-          auto *const acceptor = *acceptor_it;
+          const auto *const acceptor = *acceptor_it;
           if (acceptor->get_acceptor_id() >= get_acceptor_id())
             continue;
           bool has_trailing  = acceptor->get_section_name().back() == sep;
index fefa8fc96abd455956bf45cb93bef4c4ca9aa5f3..15ccac94b2850d98049829817b5b3d5410d3d68e 100644 (file)
@@ -315,7 +315,7 @@ namespace
     current_section.sort(compare);
 
     // Now transverse subsections tree recursively.
-    for (auto &p : current_section)
+    for (const auto &p : current_section)
       {
         if ((is_parameter_node(p.second) == false) &&
             (is_alias_node(p.second) == false))
index a132c5898ace88f68f4bf08380c8c6b2eb78c9a1..4fa894813ed77019be4a7dee0e68da43d6a3cde1 100644 (file)
@@ -156,9 +156,8 @@ BarycentricPolynomials<dim>::BarycentricPolynomials(
   const std::vector<PolyType> &polynomials)
   : ScalarPolynomialsBase<dim>(internal::get_degree<dim>(polynomials),
                                polynomials.size())
+  , polys(polynomials)
 {
-  polys = polynomials;
-
   poly_grads.resize(polynomials.size());
   poly_hessians.resize(polynomials.size());
   poly_third_derivatives.resize(polynomials.size());
index 577ef8e48b391deaeb2152bf243162ac84f6effd..281b35719ef7afa817ac165a222b44c5c889e1e1 100644 (file)
@@ -1351,13 +1351,13 @@ QGaussRadauChebyshev<1>::QGaussRadauChebyshev(const unsigned int n,
   Assert(n > 0, ExcMessage("Need at least one point for quadrature rules."));
   std::vector<double> points =
     internal::QGaussRadauChebyshev::get_quadrature_points(n, end_point);
-  std::vector<double> weights =
+  std::vector<double> new_weights =
     internal::QGaussRadauChebyshev::get_quadrature_weights(n, end_point);
 
   for (unsigned int i = 0; i < this->size(); ++i)
     {
       this->quadrature_points[i] = Point<1>(points[i]);
-      this->weights[i]           = weights[i];
+      this->weights[i]           = new_weights[i];
     }
 }
 
index 6207e6426dd219b2cab7a99a12b920ea5c0765b3..bb32bbc9ffa3cf609481f992c970f1942db32a5e 100644 (file)
@@ -90,7 +90,7 @@ namespace internal
     else
       ss.setf(std::ios::fixed, std::ios::floatfield);
 
-    std::visit([&ss](auto &v) { ss << v; }, value);
+    std::visit([&ss](const auto &v) { ss << v; }, value);
 
     cached_value = ss.str();
     if (cached_value.empty())
@@ -155,7 +155,7 @@ TableHandler::Column::pad_column_below(const unsigned int size)
   while (entries.size() < size)
     {
       entries.push_back(entries.back().get_default_constructed_copy());
-      internal::TableEntry &entry = entries.back();
+      const internal::TableEntry &entry = entries.back();
       entry.cache_string(scientific, precision);
       max_length =
         std::max(max_length,
@@ -218,7 +218,7 @@ TableHandler::start_new_row()
     while (column.second.entries.size() < max_col_length)
       {
         column.second.entries.emplace_back("");
-        internal::TableEntry &entry = column.second.entries.back();
+        const internal::TableEntry &entry = column.second.entries.back();
         entry.cache_string(column.second.scientific, column.second.precision);
         column.second.max_length =
           std::max(column.second.max_length,
@@ -701,7 +701,8 @@ TableHandler::write_tex(std::ostream &out, const bool with_header) const
           else
             out.setf(std::ios::fixed, std::ios::floatfield);
 
-          std::visit([&out](auto &v) { out << v; }, column.entries[i].value);
+          std::visit([&out](const auto &v) { out << v; },
+                     column.entries[i].value);
 
           if (j < n_cols - 1)
             out << " & ";
index 003a0a0ce865dac2d51dd2332af82a17657f726b..4485574b3368a4b8405c78fb0a3d7cfd7a68a6e5 100644 (file)
@@ -1012,8 +1012,8 @@ namespace Utilities
     std::string
     get_time()
     {
-      std::time_t time1 = std::time(nullptr);
-      std::tm    *time  = std::localtime(&time1);
+      std::time_t    time1 = std::time(nullptr);
+      const std::tm *time  = std::localtime(&time1);
 
       std::ostringstream o;
       o << time->tm_hour << ":" << (time->tm_min < 10 ? "0" : "")
@@ -1028,8 +1028,8 @@ namespace Utilities
     std::string
     get_date()
     {
-      std::time_t time1 = std::time(nullptr);
-      std::tm    *time  = std::localtime(&time1);
+      std::time_t    time1 = std::time(nullptr);
+      const std::tm *time  = std::localtime(&time1);
 
       std::ostringstream o;
       o << time->tm_year + 1900 << "/" << time->tm_mon + 1 << "/"
index af18a2aaf9f33ff17de604b0d4bb562b76f25080..8c2baebda20323e45bc162f02b6e40e2254c7466 100644 (file)
@@ -56,21 +56,13 @@ namespace internal
   {
     std::string policy_name;
     if (dynamic_cast<const typename dealii::internal::DoFHandlerImplementation::
-                       Policy::Sequential<dim, spacedim> *>(&policy) ||
-        dynamic_cast<const typename dealii::internal::DoFHandlerImplementation::
                        Policy::Sequential<dim, spacedim> *>(&policy))
       policy_name = "Policy::Sequential<";
     else if (dynamic_cast<
-               const typename dealii::internal::DoFHandlerImplementation::
-                 Policy::ParallelDistributed<dim, spacedim> *>(&policy) ||
-             dynamic_cast<
                const typename dealii::internal::DoFHandlerImplementation::
                  Policy::ParallelDistributed<dim, spacedim> *>(&policy))
       policy_name = "Policy::ParallelDistributed<";
     else if (dynamic_cast<
-               const typename dealii::internal::DoFHandlerImplementation::
-                 Policy::ParallelShared<dim, spacedim> *>(&policy) ||
-             dynamic_cast<
                const typename dealii::internal::DoFHandlerImplementation::
                  Policy::ParallelShared<dim, spacedim> *>(&policy))
       policy_name = "Policy::ParallelShared<";
index 3fd1a6641c692e22cbb376d2fb6c223161813293..f1809ebd2c67bc0f7b14446b18b1d9fe36bddc7d 100644 (file)
@@ -489,7 +489,7 @@ namespace DoFTools
           index_per_comp[comp_i].add_index(
             locally_owned_dofs.nth_index_in_set(i));
       }
-    for (auto &c : index_per_comp)
+    for (const auto &c : index_per_comp)
       c.compress();
     return index_per_comp;
   }
index 83ea9c889a467d89af81d6b159a8475853cb005c..ffd2dc6a02a8985385a466c19d4e39b2fe177fc1 100644 (file)
@@ -870,7 +870,7 @@ FE_DGQArbitraryNodes<dim, spacedim>::get_name() const
   bool                equidistant = true;
   std::vector<double> points(this->degree + 1);
 
-  auto *const polynomial_space =
+  const auto *const polynomial_space =
     dynamic_cast<TensorProductPolynomials<dim> *>(this->poly_space.get());
   Assert(polynomial_space != nullptr, ExcInternalError());
   std::vector<unsigned int> lexicographic =
@@ -987,7 +987,7 @@ FE_DGQArbitraryNodes<dim, spacedim>::clone() const
 {
   // Construct a dummy quadrature formula containing the FE's nodes:
   std::vector<Point<1>> qpoints(this->degree + 1);
-  auto *const           polynomial_space =
+  const auto *const     polynomial_space =
     dynamic_cast<TensorProductPolynomials<dim> *>(this->poly_space.get());
   Assert(polynomial_space != nullptr, ExcInternalError());
   std::vector<unsigned int> lexicographic =

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.