From cbcd0a6950ffbec0473c4620f2dc27be91e6502a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Wed, 9 Jan 2019 15:58:45 +0100 Subject: [PATCH] Port to C++11 default members initializers Performed using modernize-use-default-member-init from clang-tidy. https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-default-member-init.html --- dynare++/integ/cc/product.cc | 4 ++-- dynare++/integ/cc/product.hh | 6 +++--- dynare++/integ/cc/smolyak.cc | 2 +- dynare++/integ/cc/smolyak.hh | 2 +- dynare++/parser/cc/atom_substitutions.hh | 4 ++-- dynare++/parser/cc/dynamic_atoms.cc | 4 ---- dynare++/parser/cc/dynamic_atoms.hh | 7 ++++--- dynare++/parser/cc/location.hh | 6 +++--- dynare++/parser/cc/matrix_parser.cc | 4 ++-- dynare++/parser/cc/matrix_parser.hh | 12 ++++++------ dynare++/parser/cc/tree.hh | 10 +++++----- dynare++/src/dynare_model.cc | 4 +--- dynare++/src/dynare_model.hh | 12 ++++++------ dynare++/src/forw_subst_builder.hh | 14 ++++++-------- dynare++/src/planner_builder.hh | 11 +++++------ dynare++/sylv/cc/KronVector.hh | 8 ++++---- dynare++/sylv/cc/QuasiTriangular.hh | 6 +++--- dynare++/sylv/cc/SylvMemory.cc | 2 +- dynare++/sylv/cc/SylvMemory.hh | 8 ++++---- dynare++/sylv/cc/Vector.cc | 12 ++++++------ dynare++/sylv/cc/Vector.hh | 20 ++++++++++---------- dynare++/tl/cc/permutation.cc | 2 +- dynare++/tl/cc/permutation.hh | 4 ++-- dynare++/tl/cc/sthread.hh | 6 +++--- dynare++/tl/testing/monoms.hh | 6 +++--- dynare++/utils/cc/pascal_triangle.hh | 4 ++-- 26 files changed, 86 insertions(+), 94 deletions(-) diff --git a/dynare++/integ/cc/product.cc b/dynare++/integ/cc/product.cc index 2e8b226262..d796a374dc 100644 --- a/dynare++/integ/cc/product.cc +++ b/dynare++/integ/cc/product.cc @@ -4,8 +4,8 @@ #include "symmetry.hh" prodpit::prodpit() - : prodq(NULL), level(0), npoints(0), jseq(NULL), - end_flag(true), sig(NULL), p(NULL) + : prodq(NULL), jseq(NULL), + sig(NULL), p(NULL) { } diff --git a/dynare++/integ/cc/product.hh b/dynare++/integ/cc/product.hh index 681341261d..2265ee8263 100644 --- a/dynare++/integ/cc/product.hh +++ b/dynare++/integ/cc/product.hh @@ -39,10 +39,10 @@ class prodpit { protected: const ProductQuadrature *prodq; - int level; - int npoints; + int level{0}; + int npoints{0}; IntSequence *jseq; - bool end_flag; + bool end_flag{true}; ParameterSignal *sig; Vector *p; double w; diff --git a/dynare++/integ/cc/smolyak.cc b/dynare++/integ/cc/smolyak.cc index a07bbb2dcd..0475cea805 100644 --- a/dynare++/integ/cc/smolyak.cc +++ b/dynare++/integ/cc/smolyak.cc @@ -4,7 +4,7 @@ #include "symmetry.hh" smolpit::smolpit() - : smolq(NULL), isummand(0), jseq(NULL), sig(NULL), p(NULL) + : smolq(NULL), jseq(NULL), sig(NULL), p(NULL) { } diff --git a/dynare++/integ/cc/smolyak.hh b/dynare++/integ/cc/smolyak.hh index d5c6e59a4a..218d50a072 100644 --- a/dynare++/integ/cc/smolyak.hh +++ b/dynare++/integ/cc/smolyak.hh @@ -41,7 +41,7 @@ class smolpit { protected: const SmolyakQuadrature *smolq; - unsigned int isummand; + unsigned int isummand{0}; IntSequence *jseq; ParameterSignal *sig; Vector *p; diff --git a/dynare++/parser/cc/atom_substitutions.hh b/dynare++/parser/cc/atom_substitutions.hh index 9e44ae4e81..b46f885547 100644 --- a/dynare++/parser/cc/atom_substitutions.hh +++ b/dynare++/parser/cc/atom_substitutions.hh @@ -21,8 +21,8 @@ namespace ogp * about, this is a number of substitutions. */ struct SubstInfo { - int num_substs; - SubstInfo() : num_substs(0) + int num_substs{0}; + SubstInfo() { } }; diff --git a/dynare++/parser/cc/dynamic_atoms.cc b/dynare++/parser/cc/dynamic_atoms.cc index 6634973aba..b604d9cda0 100644 --- a/dynare++/parser/cc/dynamic_atoms.cc +++ b/dynare++/parser/cc/dynamic_atoms.cc @@ -5,9 +5,6 @@ #include "utils/cc/exception.hh" #include "dynamic_atoms.hh" -#include <cstring> -#include <climits> - using namespace ogp; NameStorage::NameStorage(const NameStorage &stor) @@ -136,7 +133,6 @@ Constants::print() const } DynamicAtoms::DynamicAtoms() - : nv(0), minlag(INT_MAX), maxlead(INT_MIN) { } diff --git a/dynare++/parser/cc/dynamic_atoms.hh b/dynare++/parser/cc/dynamic_atoms.hh index e4dd3714c6..af9d2979b2 100644 --- a/dynare++/parser/cc/dynamic_atoms.hh +++ b/dynare++/parser/cc/dynamic_atoms.hh @@ -12,6 +12,7 @@ #include <set> #include <string> #include <cstring> +#include <climits> namespace ogp { @@ -161,11 +162,11 @@ namespace ogp Tindexmap indices; /** Number of variables. */ - int nv; + int nv{0}; /** Minimum lag, if there is at least one lag, than this is a negative number. */ - int minlag; + int minlag{INT_MAX}; /** Maximum lead, if there is at least one lead, than this is a positive number. */ - int maxlead; + int maxlead{INT_MIN}; public: /** Construct empty DynamicAtoms. */ DynamicAtoms(); diff --git a/dynare++/parser/cc/location.hh b/dynare++/parser/cc/location.hh index 93b51cf170..e9ed648145 100644 --- a/dynare++/parser/cc/location.hh +++ b/dynare++/parser/cc/location.hh @@ -23,9 +23,9 @@ namespace ogp struct location_type { - int off; // offset of the token - int ll; // length ot the token - location_type() : off(0), ll(0) + int off{0}; // offset of the token + int ll{0}; // length ot the token + location_type() { } }; diff --git a/dynare++/parser/cc/matrix_parser.cc b/dynare++/parser/cc/matrix_parser.cc index f71f8248ec..052af55425 100644 --- a/dynare++/parser/cc/matrix_parser.cc +++ b/dynare++/parser/cc/matrix_parser.cc @@ -89,12 +89,12 @@ MatrixParser::end() const } MPIterator::MPIterator(const MatrixParser &mp) - : p(&mp), i(0), c(0), r(mp.find_first_non_empty_row()) + : p(&mp), i(0), r(mp.find_first_non_empty_row()) { } MPIterator::MPIterator(const MatrixParser &mp, const char *dummy) - : p(&mp), i(mp.data.size()), c(0), r(mp.row_lengths.size()) + : p(&mp), i(mp.data.size()), r(mp.row_lengths.size()) { } diff --git a/dynare++/parser/cc/matrix_parser.hh b/dynare++/parser/cc/matrix_parser.hh index e86f57f0e5..188771252d 100644 --- a/dynare++/parser/cc/matrix_parser.hh +++ b/dynare++/parser/cc/matrix_parser.hh @@ -31,10 +31,10 @@ namespace ogp /** Number of items in each row. */ vector<int> row_lengths; /** Maximum number of row lengths. */ - int nc; + int nc{0}; public: MatrixParser() - : nc(0) + { } MatrixParser(const MatrixParser &mp) @@ -87,14 +87,14 @@ namespace ogp /** Reference to the matrix parser. */ const MatrixParser *p; /** The index of the pointed item in the matrix parser. */ - unsigned int i; + unsigned int i{0}; /** The column number of the pointed item starting from zero. */ - int c; + int c{0}; /** The row number of the pointed item starting from zero. */ - int r; + int r{0}; public: - MPIterator() : p(NULL), i(0), c(0), r(0) + MPIterator() : p(NULL) { } /** Constructs an iterator pointing to the beginning of the diff --git a/dynare++/parser/cc/tree.hh b/dynare++/parser/cc/tree.hh index 9517d4a976..075b537e34 100644 --- a/dynare++/parser/cc/tree.hh +++ b/dynare++/parser/cc/tree.hh @@ -32,11 +32,11 @@ namespace ogp { protected: /** Code of the operation. */ - code_t code; + code_t code{NONE}; /** First operand. If none, then it is -1. */ - int op1; + int op1{-1}; /** Second operand. If none, then it is -1. */ - int op2; + int op2{-1}; public: /** Constructs a binary operation. */ @@ -46,12 +46,12 @@ namespace ogp } /** Constructs a unary operation. */ Operation(code_t cd, int oper1) - : code(cd), op1(oper1), op2(-1) + : code(cd), op1(oper1) { } /** Constructs a nulary operation. */ Operation() - : code(NONE), op1(-1), op2(-1) + { } /** A copy constructor. */ diff --git a/dynare++/src/dynare_model.cc b/dynare++/src/dynare_model.cc index 0d95c91cf5..f832b41aef 100644 --- a/dynare++/src/dynare_model.cc +++ b/dynare++/src/dynare_model.cc @@ -26,9 +26,7 @@ ParsedMatrix::ParsedMatrix(const ogp::MatrixParser &mp) } DynareModel::DynareModel() - : atoms(), eqs(atoms), order(-1), - param_vals(0), init_vals(0), vcov_mat(0), - t_plobjective(-1), t_pldiscount(-1), + : atoms(), eqs(atoms), pbuilder(NULL), fbuilder(NULL), atom_substs(NULL), old_atoms(NULL) { diff --git a/dynare++/src/dynare_model.hh b/dynare++/src/dynare_model.hh index 6f8c51fe33..49479ae8ca 100644 --- a/dynare++/src/dynare_model.hh +++ b/dynare++/src/dynare_model.hh @@ -83,22 +83,22 @@ namespace ogdyn /** Parsed model equations. */ ogp::FormulaParser eqs; /** Order of approximation. */ - int order; + int order{-1}; /** A vector of parameters values created by a subclass. It * is stored with natural ordering (outer) of the parameters * given by atoms. */ - Vector *param_vals; + Vector *param_vals{0}; /** A vector of initial values created by a subclass. It is * stored with internal ordering given by atoms. */ - Vector *init_vals; + Vector *init_vals{0}; /** A matrix for vcov. It is created by a subclass. */ - TwoDMatrix *vcov_mat; + TwoDMatrix *vcov_mat{0}; /** Tree index of the planner objective. If there was no * planner objective keyword, the value is set to -1. */ - int t_plobjective; + int t_plobjective{-1}; /** Tree index of the planner discount. If there was no * planner discount keyword, the value is set to -1. */ - int t_pldiscount; + int t_pldiscount{-1}; /** Pointer to PlannerBuilder, which is created only if the * planner's FOC are added to the model. */ PlannerBuilder *pbuilder; diff --git a/dynare++/src/forw_subst_builder.hh b/dynare++/src/forw_subst_builder.hh index 3b920748f4..a1782f441e 100644 --- a/dynare++/src/forw_subst_builder.hh +++ b/dynare++/src/forw_subst_builder.hh @@ -14,15 +14,13 @@ namespace ogdyn * forward substitutions. */ struct ForwSubstInfo { - int num_affected_equations; - int num_subst_terms; - int num_aux_variables; - int num_new_terms; + int num_affected_equations{0}; + int num_subst_terms{0}; + int num_aux_variables{0}; + int num_new_terms{0}; ForwSubstInfo() - : num_affected_equations(0), - num_subst_terms(0), - num_aux_variables(0), - num_new_terms(0) + + { } }; diff --git a/dynare++/src/planner_builder.hh b/dynare++/src/planner_builder.hh index a3406d05a0..ec7da3b983 100644 --- a/dynare++/src/planner_builder.hh +++ b/dynare++/src/planner_builder.hh @@ -125,13 +125,12 @@ namespace ogdyn * planner's problem. */ struct PlannerInfo { - int num_lagrange_mults; - int num_aux_variables; - int num_new_terms; + int num_lagrange_mults{0}; + int num_aux_variables{0}; + int num_new_terms{0}; PlannerInfo() - : num_lagrange_mults(0), - num_aux_variables(0), - num_new_terms(0) + + { } }; diff --git a/dynare++/sylv/cc/KronVector.hh b/dynare++/sylv/cc/KronVector.hh index b381288368..9ff6f2a3c5 100644 --- a/dynare++/sylv/cc/KronVector.hh +++ b/dynare++/sylv/cc/KronVector.hh @@ -12,11 +12,11 @@ class ConstKronVector; class KronVector : public Vector { protected: - int m; - int n; - int depth; + int m{0}; + int n{0}; + int depth{0}; public: - KronVector() : Vector((double *) 0, 0), m(0), n(0), depth(0) + KronVector() : Vector((double *) 0, 0) { } KronVector(int mm, int nn, int dp); // new instance diff --git a/dynare++/sylv/cc/QuasiTriangular.hh b/dynare++/sylv/cc/QuasiTriangular.hh index 6794f8e6db..0447f16d57 100644 --- a/dynare++/sylv/cc/QuasiTriangular.hh +++ b/dynare++/sylv/cc/QuasiTriangular.hh @@ -204,12 +204,12 @@ public: typedef _diag_iter<const Diagonal &, const DiagonalBlock &, list<DiagonalBlock>::const_iterator> const_diag_iter; typedef _diag_iter<Diagonal &, DiagonalBlock &, list<DiagonalBlock>::iterator> diag_iter; private: - int num_all; + int num_all{0}; list<DiagonalBlock> blocks; - int num_real; + int num_real{0}; void copy(const Diagonal &); public: - Diagonal() : num_all(0), num_real(0) + Diagonal() { } Diagonal(double *data, int d_size); diff --git a/dynare++/sylv/cc/SylvMemory.cc b/dynare++/sylv/cc/SylvMemory.cc index 57eee9af17..f0d4f69e18 100644 --- a/dynare++/sylv/cc/SylvMemory.cc +++ b/dynare++/sylv/cc/SylvMemory.cc @@ -21,7 +21,7 @@ SylvMemoryPool memory_pool; SylvMemoryPool::SylvMemoryPool() - : base(0), length(0), allocated(0), stack_mode(false) + { } diff --git a/dynare++/sylv/cc/SylvMemory.hh b/dynare++/sylv/cc/SylvMemory.hh index 73a35dfc7f..eaac9b613e 100644 --- a/dynare++/sylv/cc/SylvMemory.hh +++ b/dynare++/sylv/cc/SylvMemory.hh @@ -29,10 +29,10 @@ void operator delete[](void *p); class SylvMemoryPool { - char *base; - size_t length; - size_t allocated; - bool stack_mode; + char *base{0}; + size_t length{0}; + size_t allocated{0}; + bool stack_mode{false}; SylvMemoryPool(const SylvMemoryPool &); const SylvMemoryPool &operator=(const SylvMemoryPool &); public: diff --git a/dynare++/sylv/cc/Vector.cc b/dynare++/sylv/cc/Vector.cc index 026553a1c2..47ac744083 100644 --- a/dynare++/sylv/cc/Vector.cc +++ b/dynare++/sylv/cc/Vector.cc @@ -18,13 +18,13 @@ using namespace std; ZeroPad zero_pad; Vector::Vector(const Vector &v) - : len(v.length()), s(1), data(new double[len]), destroy(true) + : len(v.length()), data(new double[len]), destroy(true) { copy(v.base(), v.skip()); } Vector::Vector(const ConstVector &v) - : len(v.length()), s(1), data(new double[len]), destroy(true) + : len(v.length()), data(new double[len]), destroy(true) { copy(v.base(), v.skip()); } @@ -79,14 +79,14 @@ Vector::copy(const double *d, int inc) } Vector::Vector(Vector &v, int off, int l) - : len(l), s(v.skip()), data(v.base()+off*v.skip()), destroy(false) + : len(l), s(v.skip()), data(v.base()+off*v.skip()) { if (off < 0 || off + length() > v.length()) throw SYLV_MES_EXCEPTION("Subvector not contained in supvector."); } Vector::Vector(const Vector &v, int off, int l) - : len(l), s(1), data(new double[len]), destroy(true) + : len(l), data(new double[len]), destroy(true) { if (off < 0 || off + length() > v.length()) throw SYLV_MES_EXCEPTION("Subvector not contained in supvector."); @@ -94,12 +94,12 @@ Vector::Vector(const Vector &v, int off, int l) } Vector::Vector(GeneralMatrix &m, int col) - : len(m.numRows()), s(1), data(&(m.get(0, col))), destroy(false) + : len(m.numRows()), data(&(m.get(0, col))) { } Vector::Vector(int row, GeneralMatrix &m) - : len(m.numCols()), s(m.getLD()), data(&(m.get(row, 0))), destroy(false) + : len(m.numCols()), s(m.getLD()), data(&(m.get(row, 0))) { } diff --git a/dynare++/sylv/cc/Vector.hh b/dynare++/sylv/cc/Vector.hh index 3afd5d3894..30d0ce52e3 100644 --- a/dynare++/sylv/cc/Vector.hh +++ b/dynare++/sylv/cc/Vector.hh @@ -17,33 +17,33 @@ class ConstVector; class Vector { protected: - int len; - int s; - double *data; - bool destroy; + int len{0}; + int s{1}; + double *data{0}; + bool destroy{false}; public: - Vector() : len(0), s(1), data(0), destroy(false) + Vector() { } - Vector(int l) : len(l), s(1), data(new double[l]), destroy(true) + Vector(int l) : len(l), data(new double[l]), destroy(true) { } - Vector(Vector &v) : len(v.length()), s(v.skip()), data(v.base()), destroy(false) + Vector(Vector &v) : len(v.length()), s(v.skip()), data(v.base()) { } Vector(const Vector &v); Vector(const ConstVector &v); Vector(const double *d, int l) - : len(l), s(1), data(new double[len]), destroy(true) + : len(l), data(new double[len]), destroy(true) { copy(d, 1); } Vector(double *d, int l) - : len(l), s(1), data(d), destroy(false) + : len(l), data(d) { } Vector(double *d, int skip, int l) - : len(l), s(skip), data(d), destroy(false) + : len(l), s(skip), data(d) { } Vector(Vector &v, int off, int l); diff --git a/dynare++/tl/cc/permutation.cc b/dynare++/tl/cc/permutation.cc index d94cceedd6..5beef335ac 100644 --- a/dynare++/tl/cc/permutation.cc +++ b/dynare++/tl/cc/permutation.cc @@ -70,7 +70,7 @@ Permutation::computeSortingMap(const IntSequence &s) } PermutationSet::PermutationSet() - : order(1), size(1), pers(new const Permutation *[size]) + : pers(new const Permutation *[size]) { pers[0] = new Permutation(1); } diff --git a/dynare++/tl/cc/permutation.hh b/dynare++/tl/cc/permutation.hh index 8a684ffb01..64d151c32f 100644 --- a/dynare++/tl/cc/permutation.hh +++ b/dynare++/tl/cc/permutation.hh @@ -141,8 +141,8 @@ protected: class PermutationSet { - int order; - int size; + int order{1}; + int size{1}; const Permutation **const pers; public: PermutationSet(); diff --git a/dynare++/tl/cc/sthread.hh b/dynare++/tl/cc/sthread.hh index e449b8b40f..085398a796 100644 --- a/dynare++/tl/cc/sthread.hh +++ b/dynare++/tl/cc/sthread.hh @@ -427,16 +427,16 @@ namespace sthread { typedef typename mutex_traits<thread_impl>::_Tmutex _Tmutex; typedef typename cond_traits<thread_impl>::_Tcond _Tcond; - int counter; + int counter{0}; _Tmutex mut; _Tcond cond; - bool changed; + bool changed{true}; public: /* We initialize the counter to 0, and |changed| flag to |true|, since the counter was change from undefined value to 0. */ condition_counter() - : counter(0), changed(true) + { mutex_traits<thread_impl>::init(mut); cond_traits<thread_impl>::init(cond); diff --git a/dynare++/tl/testing/monoms.hh b/dynare++/tl/testing/monoms.hh index 684c9d4f6e..3dc285cee0 100644 --- a/dynare++/tl/testing/monoms.hh +++ b/dynare++/tl/testing/monoms.hh @@ -12,11 +12,11 @@ class IntGenerator { - int maxim; - double probab; + int maxim{5}; + double probab{0.3}; public: IntGenerator() - : maxim(5), probab(0.3) + { } void init(int nf, int ny, int nv, int nw, int nu, int mx, double prob); diff --git a/dynare++/utils/cc/pascal_triangle.hh b/dynare++/utils/cc/pascal_triangle.hh index 66b4bac6b2..a2c021fdab 100644 --- a/dynare++/utils/cc/pascal_triangle.hh +++ b/dynare++/utils/cc/pascal_triangle.hh @@ -14,10 +14,10 @@ namespace ogu class PascalRow : public vector<int> { - int k; + int k{1}; public: PascalRow() - : vector<int>(), k(1) + : vector<int>() { push_back(2); } -- GitLab