Verified Commit f5e2bfc3 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Ask GCC to warn about C-style casts (-Wold-style-cast)

Adapt the code accordingly.
parent 76e7acab
......@@ -50,7 +50,7 @@ esac
# Use C++ for testing headers
AC_LANG([C++])
AM_CXXFLAGS="-Wall -Wno-parentheses"
AM_CXXFLAGS="-Wall -Wno-parentheses -Wold-style-cast"
AC_SUBST([AM_CXXFLAGS])
# If default 'ar' is not available, try to find one with a host prefix (see ticket #145)
......
......@@ -21,7 +21,7 @@ ParameterSignal::ParameterSignal(int n)
void
ParameterSignal::signalAfter(int l)
{
for (size_t i = 0; i < std::min((size_t) l, data.size()); i++)
for (size_t i = 0; i < std::min(static_cast<size_t>(l), data.size()); i++)
data[i] = false;
for (size_t i = l; i < data.size(); i++)
data[i] = true;
......
......@@ -152,13 +152,13 @@ main(int argc, char **argv)
// put the points to the vector
std::vector<std::unique_ptr<Vector>> points;
for (smolpit qit = sq.start(level); qit != sq.end(level); ++qit)
points.push_back(std::make_unique<Vector>((const Vector &) qit.point()));
points.push_back(std::make_unique<Vector>(const_cast<const Vector &>(qit.point())));
// sort and uniq
std::sort(points.begin(), points.end(), [](auto &a, auto &b) { return a.get() < b.get(); });
auto new_end = std::unique(points.begin(), points.end());
points.erase(new_end, points.end());
std::cout << "Duplicit nodes removed: " << (unsigned long) (sq.numEvals(level)-points.size())
std::cout << "Duplicit nodes removed: " << static_cast<unsigned long>(sq.numEvals(level)-points.size())
<< std::endl;
// calculate weights and mass
......@@ -183,7 +183,7 @@ main(int argc, char **argv)
double upscale_weight = 1/(mass-discard_mass);
Vector x(vcov.nrows());
fout << std::setprecision(16);
for (int i = 0; i < (int) weights.size(); i++)
for (int i = 0; i < static_cast<int>(weights.size()); i++)
if (weights[i]/mass >= params.discard_weight)
{
// print the upscaled weight
......
......@@ -321,7 +321,7 @@ KOrder::sylvesterSolve<Storage::fold>(ctraits<Storage::fold>::Ttensor &der) cons
ctraits<Storage::unfold>::Ttensor tmp(der);
sylvesterSolve<Storage::unfold>(tmp);
ctraits<Storage::fold>::Ttensor ftmp(tmp);
der.getData() = (const Vector &) (ftmp.getData());
der.getData() = const_cast<const Vector &>(ftmp.getData());
}
void
......
......@@ -38,5 +38,9 @@ EXTRA_DIST = assign.yy csv.yy formula.yy matrix.yy namelist.yy assign.ll csv.ll
%_tab.cc %_tab.hh: %.yy
$(YACC) -W -o$*_tab.cc $<
%_tab.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast
%_ll.cc: %.ll
$(LEX) -i -o$@ $<
%_ll.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast
......@@ -51,5 +51,5 @@ asgn_wrap()
void
asgn__destroy_buffer(void* p)
{
asgn__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
asgn__delete_buffer(static_cast<YY_BUFFER_STATE>(p));
}
......@@ -32,5 +32,5 @@ csv_wrap()
void
csv__destroy_buffer(void* p)
{
csv__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
csv__delete_buffer(static_cast<YY_BUFFER_STATE>(p));
}
......@@ -69,5 +69,5 @@ fmla_wrap()
void
fmla__destroy_buffer(void* p)
{
fmla__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
fmla__delete_buffer(static_cast<YY_BUFFER_STATE>(p));
}
......@@ -59,5 +59,5 @@ matrix_wrap()
void
matrix__destroy_buffer(void* p)
{
matrix__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
matrix__delete_buffer(static_cast<YY_BUFFER_STATE>(p));
}
......@@ -49,5 +49,5 @@ namelist_wrap()
void
namelist__destroy_buffer(void* p)
{
namelist__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
namelist__delete_buffer(static_cast<YY_BUFFER_STATE>(p));
}
......@@ -32,5 +32,9 @@ EXTRA_DIST = dynglob.ll dynglob.yy
dynglob_tab.cc dynglob_tab.hh: dynglob.yy
$(YACC) -W -odynglob_tab.cc dynglob.yy
dynare__-dynglob_tab.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast
dynglob_ll.cc: dynglob.ll
$(LEX) -i -odynglob_ll.cc dynglob.ll
dynare__-dynglob_ll.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast
......@@ -63,7 +63,7 @@ Dynare::Dynare(const char *modname, int ord, double sstol, Journal &jr)
int line = 1;
int col = 0;
size_t i = 0;
while (i < contents.length() && i < (size_t) pe.offset())
while (i < contents.length() && i < static_cast<size_t>(pe.offset()))
{
if (contents[i] == '\n')
{
......@@ -187,7 +187,7 @@ Dynare::solveDeterministicSteady(Vector &steady)
{
JournalRecordPair pa(journal);
pa << "Non-linear solver for deterministic steady state" << endrec;
steady = (const Vector &) model->getInit();
steady = const_cast<const Vector &>(model->getInit());
DynareVectorFunction dvf(*this);
DynareJacobian dj(*this);
ogu::NLSolver nls(dvf, dj, 500, ss_tol, journal);
......
......@@ -46,13 +46,13 @@ DynareDynamicAtoms::parse_variable(const char *in, std::string &out, int &ll) co
{
ll = 0;
std::string str = in;
int left = str.find_first_of("({");
if (left != -1)
auto left = str.find_first_of("({");
if (left != string::npos)
{
out = str.substr(0, left);
left++;
int right = str.find_first_of(")}", left);
if ((int) string::npos == right)
auto right = str.find_first_of(")}", left);
if (string::npos == right)
throw ogp::ParserException(
string("Syntax error when parsing Dynare atom <")+in+">.", 0);
std::string tmp(str, left, right-left);
......
......@@ -42,13 +42,13 @@ DynareModel::DynareModel(const DynareModel &dm)
atom_substs(nullptr), old_atoms(nullptr)
{
if (dm.param_vals)
param_vals = new Vector((const Vector &) *(dm.param_vals));
param_vals = new Vector(const_cast<const Vector &>(*(dm.param_vals)));
if (dm.init_vals)
init_vals = new Vector((const Vector &) *(dm.init_vals));
init_vals = new Vector(const_cast<const Vector &>(*(dm.init_vals)));
if (dm.vcov_mat)
vcov_mat = new TwoDMatrix((const TwoDMatrix &) *(dm.vcov_mat));
vcov_mat = new TwoDMatrix(const_cast<const TwoDMatrix &>(*(dm.vcov_mat)));
if (dm.old_atoms)
old_atoms = new DynareDynamicAtoms((const DynareDynamicAtoms &) *(dm.old_atoms));
old_atoms = new DynareDynamicAtoms(static_cast<const DynareDynamicAtoms &>(*(dm.old_atoms)));
if (dm.atom_substs)
atom_substs = new ogp::AtomSubstitutions((*dm.atom_substs), *old_atoms, atoms);
if (dm.pbuilder)
......@@ -147,7 +147,7 @@ DynareModel::dump_model(std::ostream &os) const
// parameter values
os.precision(16);
for (int i = 0; i < (int) atoms.get_params().size(); i++)
for (int i = 0; i < static_cast<int>(atoms.get_params().size()); i++)
os << atoms.get_params()[i] << "=" << getParams()[i] << ";\n";
os << "\n\n";
......@@ -165,7 +165,7 @@ DynareModel::dump_model(std::ostream &os) const
// initval as steady state
os << "initval;\n";
for (int i = 0; i < (int) atoms.get_endovars().size(); i++)
for (int i = 0; i < static_cast<int>(atoms.get_endovars().size()); i++)
os << atoms.get_endovars()[atoms.y2outer_endo()[i]] << "=" << getInit()[i] << ";\n";
os << "end;\n";
}
......
......@@ -65,5 +65,5 @@ dynglob_wrap()
void
dynglob__destroy_buffer(void* p)
{
dynglob__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
dynglob__delete_buffer(static_cast<YY_BUFFER_STATE>(p));
}
......@@ -50,7 +50,7 @@ main(int argc, char **argv)
for (int i = 0; i < dynare.nexog(); i++)
irf_list_ind.push_back(i);
else
irf_list_ind = ((const DynareNameList &) dynare.getExogNames()).selectIndices(params.irf_list);
irf_list_ind = (static_cast<const DynareNameList &>(dynare.getExogNames())).selectIndices(params.irf_list);
// write matlab files
std::string mfile1(params.basename);
......
......@@ -196,7 +196,7 @@ VectorFunction::check_for_eval(const ConstVector &in, Vector &out) const
double
NLSolver::eval(double lambda)
{
Vector xx((const Vector &)x);
Vector xx(const_cast<const Vector &>(x));
xx.add(1-lambda, xcauchy);
xx.add(lambda, xnewton);
Vector ff(func.outDim());
......@@ -213,7 +213,7 @@ NLSolver::solve(Vector &xx, int &iter)
rec1 << "---------------------------" << endrec;
char tmpbuf[14];
x = (const Vector &) xx;
x = const_cast<const Vector &>(xx);
iter = 0;
// setup fx
Vector fx(func.outDim());
......@@ -237,10 +237,10 @@ NLSolver::solve(Vector &xx, int &iter)
Jg.zeros();
ConstTwoDMatrix(jacob).multaVec(Jg, g);
double m = -g.dot(g)/Jg.dot(Jg);
xcauchy = (const Vector &) g;
xcauchy = const_cast<const Vector &>(g);
xcauchy.mult(m);
// calculate newton step
xnewton = (const Vector &) fx;
xnewton = const_cast<const Vector &>(fx);
ConstTwoDMatrix(jacob).multInvLeft(xnewton);
xnewton.mult(-1);
......@@ -259,7 +259,7 @@ NLSolver::solve(Vector &xx, int &iter)
sprintf(tmpbuf, "%10.6g", fx.getMax());
rec3 << iter << " " << lambda << " " << tmpbuf << endrec;
}
xx = (const Vector &) x;
xx = const_cast<const Vector &>(x);
return converged;
}
......@@ -31,7 +31,7 @@ IterativeSylvester::solve(SylvParams &pars, KronVector &x) const
double
IterativeSylvester::performFirstStep(KronVector &x) const
{
KronVector xtmp((const KronVector &)x);
KronVector xtmp(const_cast<const KronVector &>(x));
KronUtils::multKron(*matrixF, *matrixK, xtmp);
x.add(-1., xtmp);
double norm = xtmp.getMax();
......@@ -42,7 +42,7 @@ double
IterativeSylvester::performStep(const QuasiTriangular &k, const QuasiTriangular &f,
KronVector &x)
{
KronVector xtmp((const KronVector &)x);
KronVector xtmp(const_cast<const KronVector &>(x));
KronUtils::multKron(f, k, xtmp);
x.add(1.0, xtmp);
double norm = xtmp.getMax();
......
......@@ -117,7 +117,7 @@ mxArray *
SylvParams::IntParamItem::createMatlabArray() const
{
mxArray *res = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
*reinterpret_cast<int *>(mxGetData(res)) = value;
*static_cast<int *>(mxGetData(res)) = value;
return res;
}
......
......@@ -70,7 +70,7 @@ TestRunnable::test() const
clock_t start = clock();
bool passed = run();
clock_t end = clock();
std::cout << "CPU time " << ((double) (end-start))/CLOCKS_PER_SEC << " (CPU seconds)..................";
std::cout << "CPU time " << (static_cast<double>(end-start))/CLOCKS_PER_SEC << " (CPU seconds)..................";
if (passed)
std::cout << "passed";
else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment