From 4a5b811b64fa476913c0e5ae622c0b87efa46e61 Mon Sep 17 00:00:00 2001 From: Ayush Kumar Date: Fri, 20 Mar 2026 00:42:06 +0530 Subject: [PATCH] clang-tidy: fix cppcoreguidelines-pro-type-member-init --- .clang-tidy | 1 - include/chinese/chinesePostman.hpp | 4 ++-- include/cpp_common/base_graph.hpp | 2 +- include/cpp_common/ch_edge.hpp | 8 ++++---- include/cpp_common/ch_vertex.hpp | 2 +- include/cpp_common/line_vertex.hpp | 10 +++++----- include/cpp_common/path.hpp | 6 +++--- include/lineGraph/lineGraphFull.hpp | 2 +- include/max_flow/maxflow.hpp | 4 ++-- include/max_flow/minCostMaxFlow.hpp | 4 ++-- include/spanningTree/mst.hpp | 6 +++--- include/trsp/edgeInfo.hpp | 4 ++-- include/trsp/trspHandler.hpp | 6 +++--- include/vrp/tw_node.hpp | 12 ++++++------ include/yen/turnRestrictedPath.hpp | 6 +++--- src/cpp_common/pgdata_fetchers.cpp | 22 +++++++++++----------- src/max_flow/minCostMaxFlow.cpp | 2 +- 17 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index aa9f598740..ad4a1e0e59 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -18,7 +18,6 @@ Checks: > -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-const-cast, - -cppcoreguidelines-pro-type-member-init, -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-vararg, diff --git a/include/chinese/chinesePostman.hpp b/include/chinese/chinesePostman.hpp index 52fdaeb46b..966edc33bb 100644 --- a/include/chinese/chinesePostman.hpp +++ b/include/chinese/chinesePostman.hpp @@ -160,7 +160,7 @@ PgrDirectedChPPGraph::PgrDirectedChPPGraph(const std::vector &dataEdges) } } - CostFlow_t edge; + CostFlow_t edge{}; edge.edge_id = e.id; edge.reverse_capacity = -1; edge.reverse_cost = -1.0; @@ -185,7 +185,7 @@ PgrDirectedChPPGraph::PgrDirectedChPPGraph(const std::vector &dataEdges) int d = iter->second; if (d == 0) continue; if (d > 0) totalDeg += d; - CostFlow_t edge = {}; + CostFlow_t edge{}; edge.reverse_capacity = -1; edge.reverse_cost = -1.0; edge.cost = 0.0; diff --git a/include/cpp_common/base_graph.hpp b/include/cpp_common/base_graph.hpp index c19f36b1a7..9ba79ae727 100644 --- a/include/cpp_common/base_graph.hpp +++ b/include/cpp_common/base_graph.hpp @@ -720,7 +720,7 @@ class Pgr_base_graph { * @return edge data */ T_E get_edge_info(const E &e) const { - T_E d_edge; + T_E d_edge{}; d_edge.id = graph[e].id; d_edge.source = graph[source(e)].id; d_edge.target = graph[target(e)].id; diff --git a/include/cpp_common/ch_edge.hpp b/include/cpp_common/ch_edge.hpp index eb1f888291..65b7d23bd2 100644 --- a/include/cpp_common/ch_edge.hpp +++ b/include/cpp_common/ch_edge.hpp @@ -63,10 +63,10 @@ class CH_edge { friend std::ostream& operator <<(std::ostream& os, const CH_edge& e); public: - int64_t id; - int64_t source; - int64_t target; - double cost; + int64_t id{}; + int64_t source{}; + int64_t target{}; + double cost{}; private: Identifiers m_contracted_vertices; diff --git a/include/cpp_common/ch_vertex.hpp b/include/cpp_common/ch_vertex.hpp index 62aa930857..0e34e46e2e 100644 --- a/include/cpp_common/ch_vertex.hpp +++ b/include/cpp_common/ch_vertex.hpp @@ -41,7 +41,7 @@ namespace pgrouting { class CH_vertex { public: - int64_t id; + int64_t id{}; CH_vertex(); CH_vertex(const Edge_t &other, bool is_source) : diff --git a/include/cpp_common/line_vertex.hpp b/include/cpp_common/line_vertex.hpp index 2ac597066b..93e9053899 100644 --- a/include/cpp_common/line_vertex.hpp +++ b/include/cpp_common/line_vertex.hpp @@ -93,11 +93,11 @@ class Line_vertex { } public: - int64_t id; - int64_t vertex_id; - int64_t source; - int64_t target; - double cost; + int64_t id{}; + int64_t vertex_id{}; + int64_t source{}; + int64_t target{}; + double cost{}; }; } // namespace pgrouting diff --git a/include/cpp_common/path.hpp b/include/cpp_common/path.hpp index 1c8ad9fb6b..a183bc7e82 100644 --- a/include/cpp_common/path.hpp +++ b/include/cpp_common/path.hpp @@ -57,9 +57,9 @@ class Path { private: std::deque< Path_t > path; - int64_t m_start_id; - int64_t m_end_id; - double m_tot_cost; + int64_t m_start_id{}; + int64_t m_end_id{}; + double m_tot_cost{}; public: Path(): m_start_id(0), m_end_id(0), m_tot_cost(0) diff --git a/include/lineGraph/lineGraphFull.hpp b/include/lineGraph/lineGraphFull.hpp index 81a3a634c6..4ec4feacb1 100644 --- a/include/lineGraph/lineGraphFull.hpp +++ b/include/lineGraph/lineGraphFull.hpp @@ -292,7 +292,7 @@ class Pgr_lineGraphFull : public Pgr_base_graph { } private: - int64_t m_num_edges; + int64_t m_num_edges{}; std::map < int64_t, double > m_edge_costs; std::map < int64_t, std::pair< int64_t, int64_t > > m_transformation_map; std::map < std::pair< int64_t, int64_t >, int64_t > m_vertex_map; diff --git a/include/max_flow/maxflow.hpp b/include/max_flow/maxflow.hpp index 3bf8301e58..8f4dfb1067 100644 --- a/include/max_flow/maxflow.hpp +++ b/include/max_flow/maxflow.hpp @@ -193,8 +193,8 @@ class PgrFlowGraph { * The same applies for sinks. * To avoid code repetition, a supersource/sink is used even in the one to one signature. */ - V supersource; - V supersink; + V supersource{}; + V supersink{}; }; } // namespace graph diff --git a/include/max_flow/minCostMaxFlow.hpp b/include/max_flow/minCostMaxFlow.hpp index 9fdf92b732..cc9de73b53 100644 --- a/include/max_flow/minCostMaxFlow.hpp +++ b/include/max_flow/minCostMaxFlow.hpp @@ -138,8 +138,8 @@ class PgrCostFlowGraph { * The same applies for sinks. * To avoid code repetition, a supersource/sink is used even in the one to one signature. */ - V supersource; - V supersink; + V supersource{}; + V supersink{}; }; } // namespace graph diff --git a/include/spanningTree/mst.hpp b/include/spanningTree/mst.hpp index 174d4b06b0..255a64a561 100644 --- a/include/spanningTree/mst.hpp +++ b/include/spanningTree/mst.hpp @@ -144,9 +144,9 @@ class Pgr_mst { protected: std::set m_roots; - bool m_get_component; - int64_t m_max_depth; - double m_distance; + bool m_get_component{}; + int64_t m_max_depth{}; + double m_distance{}; struct InSpanning { std::set edges; diff --git a/include/trsp/edgeInfo.hpp b/include/trsp/edgeInfo.hpp index c267a68395..e445fa79a4 100644 --- a/include/trsp/edgeInfo.hpp +++ b/include/trsp/edgeInfo.hpp @@ -85,8 +85,8 @@ class EdgeInfo { private: - Edge_t m_edge; - size_t m_edgeIndex; + Edge_t m_edge{}; + size_t m_edgeIndex{}; std::vector m_startConnectedEdge; std::vector m_endConnectedEdge; }; diff --git a/include/trsp/trspHandler.hpp b/include/trsp/trspHandler.hpp index b02f29b869..edebdbec13 100644 --- a/include/trsp/trspHandler.hpp +++ b/include/trsp/trspHandler.hpp @@ -172,13 +172,13 @@ class TrspHandler : public pgrouting::Pgr_messages { /* idx -> id */ std::map m_idx_to_id; - int64_t m_start_vertex; - int64_t m_end_vertex; + int64_t m_start_vertex{}; + int64_t m_end_vertex{}; /* * Used in dijkstra_exploration */ - int64_t m_current_node; + int64_t m_current_node{}; Path m_path; diff --git a/include/vrp/tw_node.hpp b/include/vrp/tw_node.hpp index 40e5cad8f9..47482e7f8c 100644 --- a/include/vrp/tw_node.hpp +++ b/include/vrp/tw_node.hpp @@ -221,12 +221,12 @@ class Tw_node : public Dnode { private: - int64_t m_order; ///< order to which it belongs - double m_opens; ///< opening time of the node - double m_closes; ///< closing time of the node - double m_service_time; // /< time it takes to be served - double m_demand; ///< The demand for the Node - NodeType m_type; ///< The demand for the Node + int64_t m_order{}; ///< order to which it belongs + double m_opens{}; ///< opening time of the node + double m_closes{}; ///< closing time of the node + double m_service_time{}; ///< time it takes to be served + double m_demand{}; ///< The demand for the Node + NodeType m_type{}; ///< The type for the Node }; } // namespace vrp diff --git a/include/yen/turnRestrictedPath.hpp b/include/yen/turnRestrictedPath.hpp index 7255fad6aa..96d566cdf9 100644 --- a/include/yen/turnRestrictedPath.hpp +++ b/include/yen/turnRestrictedPath.hpp @@ -254,10 +254,10 @@ class Pgr_turnRestrictedPath : public Pgr_ksp< G > { private: std::vector m_restrictions; - bool m_strict; + bool m_strict{}; pSet m_solutions; - bool m_stop_on_first; - bool m_heap_paths; + bool m_stop_on_first{}; + bool m_heap_paths{}; }; } // namespace yen diff --git a/src/cpp_common/pgdata_fetchers.cpp b/src/cpp_common/pgdata_fetchers.cpp index 0a084dc352..25c2161a23 100644 --- a/src/cpp_common/pgdata_fetchers.cpp +++ b/src/cpp_common/pgdata_fetchers.cpp @@ -68,7 +68,7 @@ II_t_rt fetch_combination( int64_t*, size_t*, bool) { - II_t_rt combination; + II_t_rt combination{}; combination.d1.source = getBigInt(tuple, tupdesc, info[0]); combination.d2.target = getBigInt(tuple, tupdesc, info[1]); return combination; @@ -81,7 +81,7 @@ Coordinate_t fetch_coordinate( int64_t *default_id, size_t*, bool) { - Coordinate_t coordinate; + Coordinate_t coordinate{}; if (column_found(info[0].colNumber)) { coordinate.id = getBigInt(tuple, tupdesc, info[0]); } else { @@ -100,7 +100,7 @@ Delauny_t fetch_delauny( int64_t*, size_t*, bool) { - Delauny_t delauny; + Delauny_t delauny{}; delauny.tid = getBigInt(tuple, tupdesc, info[0]); delauny.pid = getBigInt(tuple, tupdesc, info[1]); delauny.x = getFloat8(tuple, tupdesc, info[2]); @@ -117,7 +117,7 @@ Edge_bool_t fetch_basic_edge( int64_t *default_id, size_t *valid_edges, bool) { - Edge_bool_t edge; + Edge_bool_t edge{}; if (column_found(info[0].colNumber)) { edge.id = getBigInt(tuple, tupdesc, info[0]); } else { @@ -150,7 +150,7 @@ Edge_t fetch_edge( int64_t *default_id, size_t *valid_edges, bool normal) { - Edge_t edge; + Edge_t edge{}; if (column_found(info[0].colNumber)) { edge.id = getBigInt(tuple, tupdesc, info[0]); } else { @@ -194,7 +194,7 @@ CostFlow_t fetch_costFlow_edge( int64_t *default_id, size_t *valid_edges, bool normal) { - CostFlow_t edge; + CostFlow_t edge{}; if (column_found(info[0].colNumber)) { edge.edge_id = getBigInt(tuple, tupdesc, info[0]); } else { @@ -236,7 +236,7 @@ Edge_xy_t fetch_edge_xy( int64_t *default_id, size_t *valid_edges, bool normal) { - Edge_xy_t edge; + Edge_xy_t edge{}; if (column_found(info[0].colNumber)) { edge.id = getBigInt(tuple, tupdesc, info[0]); } else { @@ -276,7 +276,7 @@ IID_t_rt pgr_fetch_row( int64_t*, size_t*, bool) { - IID_t_rt distance; + IID_t_rt distance{}; distance.from_vid = getBigInt(tuple, tupdesc, info[0]); distance.to_vid = getBigInt(tuple, tupdesc, info[1]); distance.cost = getFloat8(tuple, tupdesc, info[2]); @@ -291,7 +291,7 @@ Orders_t fetch_orders( int64_t*, size_t*, bool with_id) { - Orders_t pd_order; + Orders_t pd_order{}; pd_order.id = getBigInt(tuple, tupdesc, info[0]); pd_order.demand = getFloat8(tuple, tupdesc, info[1]); @@ -334,7 +334,7 @@ Restriction_t fetch_restriction( int64_t*, size_t*, bool) { - Restriction_t restriction; + Restriction_t restriction{}; restriction.cost = getFloat8(tuple, tupdesc, info[0]); restriction.via = NULL; @@ -377,7 +377,7 @@ Vehicle_t fetch_vehicle( int64_t*, size_t*, bool with_id) { - Vehicle_t vehicle; + Vehicle_t vehicle{}; vehicle.id = getBigInt(tuple, tupdesc, info[0]); vehicle.capacity = getFloat8(tuple, tupdesc, info[1]); diff --git a/src/max_flow/minCostMaxFlow.cpp b/src/max_flow/minCostMaxFlow.cpp index 55edf98176..4c549d4c83 100644 --- a/src/max_flow/minCostMaxFlow.cpp +++ b/src/max_flow/minCostMaxFlow.cpp @@ -145,7 +145,7 @@ PgrCostFlowGraph::GetFlowEdges() const { if (((capacity[*e] - residual_capacity[*e]) > 0) && ((*e).m_source != supersource) && ((*e).m_target != supersink)) { - Flow_t edge; + Flow_t edge{}; edge.edge = GetEdgeId(*e); edge.source = GetVertexId((*e).m_source); edge.target = GetVertexId((*e).m_target);