Skip to content

Commit 658c814

Browse files
committed
clang-tidy: check and fix cppcoreguidelines-use-default-member-init
- Enable cppcoreguidelines-use-default-member-init check in .clang-tidy - Use default member initializers instead of constructor initialization for: Pgr_bdAstar, PgrDirectedChPPGraph, Pgr_contractionGraph, Pgr_bidirectional, dijkstra_distance_visitor_no_init, Solution, Pgr_ksp Fixes #3041
1 parent 38f3750 commit 658c814

File tree

9 files changed

+17
-30
lines changed

9 files changed

+17
-30
lines changed

.clang-tidy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Checks: >
2525
-cppcoreguidelines-pro-type-union-access,
2626
-cppcoreguidelines-pro-type-vararg,
2727
-cppcoreguidelines-slicing,
28-
-cppcoreguidelines-special-member-functions,
29-
-cppcoreguidelines-use-default-member-init
28+
-cppcoreguidelines-special-member-functions
3029
3130
CheckOptions:
3231
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor

include/bdAstar/bdAstar.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ class Pgr_bdAstar : public Pgr_bidirectional<G> {
7272

7373
public:
7474
explicit Pgr_bdAstar(G &pgraph) :
75-
Pgr_bidirectional<G>(pgraph),
76-
m_heuristic(5),
77-
m_factor(1.0) {
75+
Pgr_bidirectional<G>(pgraph) {
7876
m_log << "pgr_bdAstar constructor\n";
7977
}
8078

@@ -184,8 +182,8 @@ class Pgr_bdAstar : public Pgr_bidirectional<G> {
184182
}
185183

186184
private:
187-
int m_heuristic;
188-
double m_factor;
185+
int m_heuristic{5};
186+
double m_factor{1.0};
189187
};
190188

191189
} // namespace bidirectional

include/chinese/chinesePostman.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class PgrDirectedChPPGraph {
7070
void setPathEdges(graph::PgrCostFlowGraph &flowGraph);
7171

7272
private:
73-
int64_t totalDeg;
74-
double totalCost;
73+
int64_t totalDeg{0};
74+
double totalCost{0};
7575
int64_t superSource, superTarget;
7676
int64_t startPoint;
7777
double m_cost;
@@ -106,7 +106,7 @@ PgrDirectedChPPGraph::~PgrDirectedChPPGraph() {
106106
edgeToIdx.clear();
107107
}
108108
PgrDirectedChPPGraph::PgrDirectedChPPGraph(const std::vector<Edge_t> &dataEdges) :
109-
totalDeg(0), totalCost(0), vertices(),
109+
vertices(),
110110
edgeToIdx(), originalEdges(),
111111
resultGraph(), VToVecid(), edgeVisited(),
112112
pathStack(), resultPath(),

include/contraction/contractionGraph.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge, t_dire
6666
Prepares the _graph_ to be of type *directed*
6767
*/
6868
explicit Pgr_contractionGraph()
69-
: Pgr_base_graph<G, CH_vertex, CH_edge, t_directed>(),
70-
min_edge_id(0) {
69+
: Pgr_base_graph<G, CH_vertex, CH_edge, t_directed>() {
7170
}
7271

7372
/*! @brief get the vertex descriptors of adjacent vertices of *v*
@@ -548,7 +547,7 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge, t_dire
548547
}
549548

550549
private:
551-
int64_t min_edge_id;
550+
int64_t min_edge_id{0};
552551
Identifiers<V> forbiddenVertices;
553552
};
554553

include/cpp_common/bidirectional.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ class Pgr_bidirectional {
7373
public:
7474
explicit Pgr_bidirectional(G &pgraph):
7575
graph(pgraph),
76-
INF((std::numeric_limits<double>::max)()),
77-
best_cost(0) {
76+
INF((std::numeric_limits<double>::max)()) {
7877
m_log << "constructor\n";
7978
}
8079

@@ -222,7 +221,7 @@ class Pgr_bidirectional {
222221

223222
double INF; //!< infinity
224223

225-
double best_cost;
224+
double best_cost{0};
226225

227226
mutable std::ostringstream m_log;
228227
Priority_queue forward_queue;

include/visitors/dijkstra_visitors.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ class dijkstra_distance_visitor_no_init : public boost::default_dijkstra_visitor
147147
std::vector<boost::default_color_type> &color_map) :
148148
m_root(root),
149149
m_distance_goal(distance_goal),
150-
m_num_examined(0),
151150
m_predecessors(predecessors),
152151
m_dist(distances),
153152
m_color(color_map) {
@@ -190,7 +189,7 @@ class dijkstra_distance_visitor_no_init : public boost::default_dijkstra_visitor
190189
private:
191190
V m_root;
192191
double m_distance_goal;
193-
size_t m_num_examined;
192+
size_t m_num_examined{0};
194193
std::vector<V > &m_predecessors;
195194
std::vector<double> &m_dist;
196195
std::vector<boost::default_color_type> &m_color;

include/vrp/solution.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Solution {
4646
friend class Optimize;
4747
friend class PD_problem;
4848
protected:
49-
double EPSILON;
49+
double EPSILON{0.0001};
5050
std::deque<Vehicle_pickDeliver> fleet;
5151

5252
/* this solution belongs to this problem*/
@@ -66,14 +66,12 @@ class Solution {
6666

6767
/* @brief copy constructor */
6868
Solution(const Solution &sol) :
69-
EPSILON(0.0001),
7069
fleet(sol.fleet),
7170
trucks(sol.trucks)
7271
{};
7372

7473
/* @brief copy assignment */
7574
Solution& operator = (const Solution& sol) {
76-
EPSILON = 0.0001,
7775
fleet = sol.fleet;
7876
trucks = sol.trucks;
7977
return *this;

include/yen/ksp.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ class Pgr_ksp : public Pgr_messages {
5959

6060
public:
6161
Pgr_ksp() :
62-
m_start(0),
63-
m_end(0),
64-
m_K(0),
65-
m_heap_paths(false),
6662
m_vis(new Visitor) {
6763
}
6864
~Pgr_ksp() {
@@ -229,10 +225,10 @@ class Pgr_ksp : public Pgr_messages {
229225
///@{
230226
V v_source; //!< source descriptor
231227
V v_target; //!< target descriptor
232-
int64_t m_start; //!< source id
233-
int64_t m_end; //!< target id
234-
size_t m_K;
235-
bool m_heap_paths;
228+
int64_t m_start{0}; //!< source id
229+
int64_t m_end{0}; //!< target id
230+
size_t m_K{0};
231+
bool m_heap_paths{false};
236232

237233
Path curr_result_path; //!< storage for the current result
238234

src/pickDeliver/solution.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ Solution::get_kind() const {
230230
}
231231

232232
Solution::Solution() :
233-
EPSILON(0.0001),
234233
trucks(problem->trucks()) {
235234
ENTERING(msg());
236235
for (const auto &t : trucks) {

0 commit comments

Comments
 (0)