From 5bda1ae18a61228618ffc258d0f50f30580fe09e Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Sat, 15 Jun 2019 14:18:15 +0200
Subject: [PATCH] Fix variable shadowing.

Either by renaming or removing the variable or adding
an extra scope to the top variable.

CPPCheck warning type: shadowVar.
---
 Applications/FileIO/SWMM/SWMMInterface.cpp    | 20 ++++++----
 .../Utils/FileConverter/MeshToRaster.cpp      | 17 +++++----
 ...CreateBoundaryConditionsAlongPolylines.cpp | 17 +++++----
 .../Utils/MeshEdit/NodeReordering.cpp         |  6 +--
 .../Utils/MeshEdit/UnityPreprocessing.cpp     |  4 +-
 .../PartitionMesh/PartitionMesh.cpp           | 12 +++---
 MeshLib/MeshGenerators/VtkMeshConverter.cpp   | 20 +++++-----
 .../ComponentTransportFEM.h                   |  7 ++--
 ProcessLib/DeactivatedSubdomain.cpp           |  4 +-
 ProcessLib/LIE/Common/MeshUtils.cpp           | 38 +++++++++----------
 10 files changed, 78 insertions(+), 67 deletions(-)

diff --git a/Applications/FileIO/SWMM/SWMMInterface.cpp b/Applications/FileIO/SWMM/SWMMInterface.cpp
index f1dfafc4b9c..0b5b4cc27a8 100644
--- a/Applications/FileIO/SWMM/SWMMInterface.cpp
+++ b/Applications/FileIO/SWMM/SWMMInterface.cpp
@@ -415,11 +415,13 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name,
     }
 
     auto name_id_map = std::make_unique<std::map<std::string, std::size_t>>();
-    std::size_t const n_names (pnt_names.size());
-    for (std::size_t i=0; i<n_names; ++i)
     {
-        if (!pnt_names[i].empty())
-            name_id_map->insert(std::make_pair(pnt_names[i], i));
+        std::size_t const n_names(pnt_names.size());
+        for (std::size_t i = 0; i < n_names; ++i)
+        {
+            if (!pnt_names[i].empty())
+                name_id_map->insert(std::make_pair(pnt_names[i], i));
+        }
     }
 
     // rewind stream and read links between junctions
@@ -467,9 +469,13 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name,
         }
         auto line_id_map =
             std::make_unique<std::map<std::string, std::size_t>>();
-        std::size_t const n_names (line_names.size());
-        for (std::size_t i=0; i<n_names; ++i)
-            line_id_map->insert(std::make_pair(line_names[i], i));
+        {
+            std::size_t const n_names(line_names.size());
+            for (std::size_t i = 0; i < n_names; ++i)
+            {
+                line_id_map->insert(std::make_pair(line_names[i], i));
+            }
+        }
         std::vector<std::size_t> const& pnt_id_map (geo_objects.getPointVecObj(geo_name)->getIDMap());
         for (GeoLib::Polyline* line : *lines)
         {
diff --git a/Applications/Utils/FileConverter/MeshToRaster.cpp b/Applications/Utils/FileConverter/MeshToRaster.cpp
index 4b355b17b3a..355f5ddd1c2 100644
--- a/Applications/Utils/FileConverter/MeshToRaster.cpp
+++ b/Applications/Utils/FileConverter/MeshToRaster.cpp
@@ -94,13 +94,13 @@ int main(int argc, char* argv[])
     MeshLib::MeshElementGrid const grid(*mesh);
     double const max_edge(mesh->getMaxEdgeLength() + cellsize);
 
-    for (std::size_t j = 0; j <= n_rows; ++j)
+    for (std::size_t row = 0; row <= n_rows; ++row)
     {
-        double const y = max[1] - j * cellsize;
-        for (std::size_t i = 0; i <= n_cols; ++i)
+        double const y = max[1] - row * cellsize;
+        for (std::size_t column = 0; column <= n_cols; ++column)
         {
             // pixel values
-            double const x = min[0] + i * cellsize;
+            double const x = min[0] + column * cellsize;
             MeshLib::Node const node(x, y, 0);
             MathLib::Point3d min_vol{{x - max_edge, y - max_edge,
                                       -std::numeric_limits<double>::max()}};
@@ -127,12 +127,15 @@ int main(int argc, char* argv[])
                 // element
                 for (std::size_t i = 0; i < 4; ++i)
                 {
-                    MeshLib::Node const node(x + x_off[i], y + y_off[i], 0);
+                    MeshLib::Node const corner_node(x + x_off[i], y + y_off[i],
+                                                    0);
                     auto const* corner_element =
-                        MeshLib::ProjectPointOnMesh::getProjectedElement(elems, node);
+                        MeshLib::ProjectPointOnMesh::getProjectedElement(
+                            elems, corner_node);
                     if (corner_element != nullptr)
                     {
-                        sum += MeshLib::ProjectPointOnMesh::getElevation( *corner_element, node);
+                        sum += MeshLib::ProjectPointOnMesh::getElevation(
+                            *corner_element, corner_node);
                         nonzero_count++;
                     }
                 }
diff --git a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp
index 0d465e9cf17..30cfb059bc6 100644
--- a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp
+++ b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp
@@ -231,9 +231,9 @@ int main (int argc, char* argv[])
         {
             continue;
         }
-        std::string geo_name("Polyline-"+std::to_string(k));
-        convertMeshNodesToGeometry(surface_mesh->getNodes(), ids, geo_name,
-            geometry_sets);
+        std::string polyline_name("Polyline-" + std::to_string(k));
+        convertMeshNodesToGeometry(surface_mesh->getNodes(), ids, polyline_name,
+                                   geometry_sets);
     }
 
     // merge all together
@@ -271,11 +271,12 @@ int main (int argc, char* argv[])
     // insert first point
     surface_pnts->push_back(
         new GeoLib::Point(pnts_with_id[0], surface_pnts->size()));
-    std::string element_name;
-    pnt_vec->getNameOfElementByID(0, element_name);
-    name_id_map->insert(
-        std::pair<std::string, std::size_t>(element_name,0)
-    );
+    {
+        std::string element_name;
+        pnt_vec->getNameOfElementByID(0, element_name);
+        name_id_map->insert(
+            std::pair<std::string, std::size_t>(element_name, 0));
+    }
     for (std::size_t k(1); k < n_merged_pnts; ++k) {
         const GeoLib::Point& p0 (pnts_with_id[k-1]);
         const GeoLib::Point& p1 (pnts_with_id[k]);
diff --git a/Applications/Utils/MeshEdit/NodeReordering.cpp b/Applications/Utils/MeshEdit/NodeReordering.cpp
index 5ca4dde0477..b983c489245 100644
--- a/Applications/Utils/MeshEdit/NodeReordering.cpp
+++ b/Applications/Utils/MeshEdit/NodeReordering.cpp
@@ -93,10 +93,10 @@ void reorderNodes2(std::vector<MeshLib::Element*> &elements)
         {
             if (elements[i]->getGeomType() == MeshLib::MeshElemType::PRISM)
             {
-                for(std::size_t j = 0; j < 3; ++j)
+                for (std::size_t k = 0; k < 3; ++k)
                 {
-                    elements[i]->setNode(j, nodes[j+3]);
-                    elements[i]->setNode(j+3, nodes[j]);
+                    elements[i]->setNode(k, nodes[k + 3]);
+                    elements[i]->setNode(k + 3, nodes[k]);
                 }
                 break;
             }
diff --git a/Applications/Utils/MeshEdit/UnityPreprocessing.cpp b/Applications/Utils/MeshEdit/UnityPreprocessing.cpp
index bfc284d22ea..2214d57736f 100644
--- a/Applications/Utils/MeshEdit/UnityPreprocessing.cpp
+++ b/Applications/Utils/MeshEdit/UnityPreprocessing.cpp
@@ -84,8 +84,8 @@ bool fillPropVec(MeshLib::Properties const& props,
         std::size_t const n_nodes (node_map.size());
         for (std::size_t i = 0; i<n_nodes; ++i)
         {
-            std::size_t const n_nodes = node_map[i].size();
-            for (std::size_t j = 0; j < n_nodes; ++j)
+            std::size_t const n_nodes_i = node_map[i].size();
+            for (std::size_t j = 0; j < n_nodes_i; ++j)
             {
                 (*new_vec)[node_map[i][j]] = (*vec)[i];
             }
diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp
index fbdfd3fcf11..562a297c4ad 100644
--- a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp
+++ b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp
@@ -179,9 +179,10 @@ int main(int argc, char* argv[])
              mesh->getNumberOfNodes(),
              mesh->getNumberOfElements());
 
-        std::string const output_file_name_wo_extension = BaseLib::joinPaths(
-            output_directory_arg.getValue(),
-            BaseLib::extractBaseNameWithoutExtension(filename));
+        std::string const other_mesh_output_file_name_wo_extension =
+            BaseLib::joinPaths(
+                output_directory_arg.getValue(),
+                BaseLib::extractBaseNameWithoutExtension(filename));
         auto const partitions = mesh_partitioner.partitionOtherMesh(
             *mesh, is_mixed_high_order_linear_elems);
 
@@ -195,8 +196,9 @@ int main(int argc, char* argv[])
             partitioned_properties.getPropertyVector<std::size_t>(
                 "bulk_element_ids", MeshLib::MeshItemType::Cell, 1),
             partitions);
-        mesh_partitioner.writeOtherMesh(output_file_name_wo_extension,
-                                        partitions, partitioned_properties);
+        mesh_partitioner.writeOtherMesh(
+            other_mesh_output_file_name_wo_extension, partitions,
+            partitioned_properties);
     }
 
     if (ascii_flag.getValue())
diff --git a/MeshLib/MeshGenerators/VtkMeshConverter.cpp b/MeshLib/MeshGenerators/VtkMeshConverter.cpp
index 7def6a68af6..ad773365b1e 100644
--- a/MeshLib/MeshGenerators/VtkMeshConverter.cpp
+++ b/MeshLib/MeshGenerators/VtkMeshConverter.cpp
@@ -154,10 +154,10 @@ MeshLib::Mesh* VtkMeshConverter::convertUnstructuredGrid(
             case VTK_WEDGE:
             {
                 auto** prism_nodes = new MeshLib::Node*[6];
-                for (unsigned i = 0; i < 3; ++i)
+                for (unsigned j = 0; j < 3; ++j)
                 {
-                    prism_nodes[i] = nodes[node_ids->GetId(i + 3)];
-                    prism_nodes[i + 3] = nodes[node_ids->GetId(i)];
+                    prism_nodes[j] = nodes[node_ids->GetId(j + 3)];
+                    prism_nodes[j + 3] = nodes[node_ids->GetId(j)];
                 }
                 elem = new MeshLib::Prism(prism_nodes, i);
                 break;
@@ -208,21 +208,21 @@ MeshLib::Mesh* VtkMeshConverter::convertUnstructuredGrid(
             case VTK_QUADRATIC_WEDGE:
             {
                 auto** prism_nodes = new MeshLib::Node*[15];
-                for (unsigned i = 0; i < 3; ++i)
+                for (unsigned j = 0; j < 3; ++j)
                 {
-                    prism_nodes[i] = nodes[node_ids->GetId(i + 3)];
-                    prism_nodes[i + 3] = nodes[node_ids->GetId(i)];
+                    prism_nodes[j] = nodes[node_ids->GetId(j + 3)];
+                    prism_nodes[j + 3] = nodes[node_ids->GetId(j)];
                 }
-                for (unsigned i = 0; i < 3; ++i)
+                for (unsigned j = 0; j < 3; ++j)
                 {
-                    prism_nodes[6 + i] = nodes[node_ids->GetId(8 - i)];
+                    prism_nodes[6 + j] = nodes[node_ids->GetId(8 - j)];
                 }
                 prism_nodes[9] = nodes[node_ids->GetId(12)];
                 prism_nodes[10] = nodes[node_ids->GetId(14)];
                 prism_nodes[11] = nodes[node_ids->GetId(13)];
-                for (unsigned i = 0; i < 3; ++i)
+                for (unsigned j = 0; j < 3; ++j)
                 {
-                    prism_nodes[12 + i] = nodes[node_ids->GetId(11 - i)];
+                    prism_nodes[12 + j] = nodes[node_ids->GetId(11 - j)];
                 }
                 elem = new MeshLib::Prism15(prism_nodes, i);
                 break;
diff --git a/ProcessLib/ComponentTransport/ComponentTransportFEM.h b/ProcessLib/ComponentTransport/ComponentTransportFEM.h
index 26320aaa0aa..58b4ad43546 100644
--- a/ProcessLib/ComponentTransport/ComponentTransportFEM.h
+++ b/ProcessLib/ComponentTransport/ComponentTransportFEM.h
@@ -346,7 +346,6 @@ public:
             auto const N_t_N = (N.transpose() * N).eval();
             if (_process_data.non_advective_form)
             {
-                const double C_int_pt(N.dot(C_nodal_values));
                 MCp.noalias() += N_t_N * (C_int_pt * R_times_phi * drho_dp * w);
                 MCC.noalias() += N_t_N * (C_int_pt * R_times_phi * drho_dC * w);
                 KCC.noalias() -= dNdx.transpose() * mass_density_flow * N * w;
@@ -812,15 +811,15 @@ public:
             auto const fe = NumLib::createIsoparametricFiniteElement<
                 ShapeFunction, ShapeMatricesType>(_element);
 
-            typename ShapeMatricesType::ShapeMatrices shape_matrices(
+            typename ShapeMatricesType::ShapeMatrices sm(
                 ShapeFunction::DIM, GlobalDim, ShapeFunction::NPOINTS);
 
             // Note: Axial symmetry is set to false here, because we only need
             // dNdx here, which is not affected by axial symmetry.
             fe.template computeShapeFunctions<NumLib::ShapeMatrixType::DNDX>(
-                pnt_local_coords.getCoords(), shape_matrices, GlobalDim, false);
+                pnt_local_coords.getCoords(), sm, GlobalDim, false);
 
-            return shape_matrices;
+            return sm;
         }();
 
         ParameterLib::SpatialPosition pos;
diff --git a/ProcessLib/DeactivatedSubdomain.cpp b/ProcessLib/DeactivatedSubdomain.cpp
index 26487b9ef30..132e10a36f2 100644
--- a/ProcessLib/DeactivatedSubdomain.cpp
+++ b/ProcessLib/DeactivatedSubdomain.cpp
@@ -107,9 +107,9 @@ std::unique_ptr<DeactivatedSubdomain const> createDeactivatedSubdomain(
             deactivated_elements.push_back(
                 const_cast<MeshLib::Element*>(element));
 
-            for (unsigned i = 0; i < element->getNumberOfNodes(); i++)
+            for (unsigned j = 0; j < element->getNumberOfNodes(); j++)
             {
-                auto const* const node = element->getNode(i);
+                auto const* const node = element->getNode(j);
                 const auto& connected_elements = node->getElements();
 
                 if (deactivation_flag_of_nodes[node->getID()])
diff --git a/ProcessLib/LIE/Common/MeshUtils.cpp b/ProcessLib/LIE/Common/MeshUtils.cpp
index 73b391801af..0f8af04aeba 100644
--- a/ProcessLib/LIE/Common/MeshUtils.cpp
+++ b/ProcessLib/LIE/Common/MeshUtils.cpp
@@ -108,11 +108,11 @@ void findFracutreIntersections(
 
     // find branch/junction nodes which connect to multiple fractures
     intersected_fracture_elements.resize(n_fractures);
-    for (auto entry : frac_nodeID_to_matIDs)
+    for (auto frac_nodeID_to_matID : frac_nodeID_to_matIDs)
     {
-        auto nodeID = entry.first;
-        auto const* node = mesh.getNode(entry.first);
-        auto const& matIDs = entry.second;
+        auto nodeID = frac_nodeID_to_matID.first;
+        auto const* node = mesh.getNode(frac_nodeID_to_matID.first);
+        auto const& matIDs = frac_nodeID_to_matID.second;
         if (matIDs.size() < 2)
         {
             continue;  // no intersection
@@ -159,9 +159,9 @@ void findFracutreIntersections(
 
         bool isBranch = false;
         {
-            for (auto entry : vec_matID_counts)
+            for (auto vec_matID_count : vec_matID_counts)
             {
-                auto count = entry.second;
+                auto count = vec_matID_count.second;
                 if (count % 2 == 1)
                 {
                     isBranch = true;
@@ -172,30 +172,30 @@ void findFracutreIntersections(
 
         if (isBranch)
         {
-            std::vector<int> matIDs(2);
-            for (auto entry : vec_matID_counts)
+            std::vector<int> branch_matIDs(2);
+            for (auto vec_matID_count : vec_matID_counts)
             {
-                auto matid = entry.first;
-                auto count = entry.second;
+                auto matid = vec_matID_count.first;
+                auto count = vec_matID_count.second;
                 if (count % 2 == 0)
                 {
-                    matIDs[0] = matid;  // master
+                    branch_matIDs[0] = matid;  // master
                 }
                 else
                 {
-                    matIDs[1] = matid;  // slave
+                    branch_matIDs[1] = matid;  // slave
                 }
             }
-            vec_branch_nodeID_matIDs.emplace_back(nodeID, matIDs);
+            vec_branch_nodeID_matIDs.emplace_back(nodeID, branch_matIDs);
         }
         else
         {
-            std::vector<int> matIDs(2);
-            matIDs[0] = std::min(vec_matID_counts.begin()->first,
-                                 vec_matID_counts.rbegin()->first);
-            matIDs[1] = std::max(vec_matID_counts.begin()->first,
-                                 vec_matID_counts.rbegin()->first);
-            vec_junction_nodeID_matIDs.emplace_back(nodeID, matIDs);
+            std::vector<int> junction_matIDs(2);
+            junction_matIDs[0] = std::min(vec_matID_counts.begin()->first,
+                                          vec_matID_counts.rbegin()->first);
+            junction_matIDs[1] = std::max(vec_matID_counts.begin()->first,
+                                          vec_matID_counts.rbegin()->first);
+            vec_junction_nodeID_matIDs.emplace_back(nodeID, junction_matIDs);
         }
     }
 
-- 
GitLab