Build system: enable the dangling else warning (-Wdangling-else)
Adapt the code accordingly.master
parent
6caf8c6c59
commit
1b7b70ec93
|
@ -43,7 +43,7 @@ esac
|
|||
# Use C++ for testing headers
|
||||
AC_LANG([C++])
|
||||
|
||||
AM_CXXFLAGS="-std=gnu++20 -Wall -Wno-dangling-else -Wextra -Wold-style-cast"
|
||||
AM_CXXFLAGS="-std=gnu++20 -Wall -Wextra -Wold-style-cast"
|
||||
AC_SUBST([AM_CXXFLAGS])
|
||||
|
||||
# If default 'ar' is not available, try to find one with a host prefix (see ticket #145)
|
||||
|
|
|
@ -148,13 +148,15 @@ ConfigFile::getConfigFileInfo(const filesystem::path &config_file)
|
|||
#endif
|
||||
configFile.open(defaultConfigFile, fstream::in);
|
||||
if (!configFile.is_open())
|
||||
if (parallel || parallel_test)
|
||||
{
|
||||
cerr << "ERROR: Could not open the default config file (" << defaultConfigFile.string() << ")" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
return;
|
||||
{
|
||||
if (parallel || parallel_test)
|
||||
{
|
||||
cerr << "ERROR: Could not open the default config file (" << defaultConfigFile.string() << ")" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -396,13 +398,15 @@ ConfigFile::getConfigFileInfo(const filesystem::path &config_file)
|
|||
if (!begin_weight)
|
||||
{
|
||||
if (!node_name.empty())
|
||||
if (member_nodes.contains(node_name))
|
||||
{
|
||||
cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
member_nodes[node_name] = 1.0;
|
||||
{
|
||||
if (member_nodes.contains(node_name))
|
||||
{
|
||||
cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
member_nodes[node_name] = 1.0;
|
||||
}
|
||||
node_name = token;
|
||||
}
|
||||
else
|
||||
|
@ -423,13 +427,15 @@ ConfigFile::getConfigFileInfo(const filesystem::path &config_file)
|
|||
}
|
||||
}
|
||||
if (!node_name.empty())
|
||||
if (!member_nodes.contains(node_name))
|
||||
member_nodes[node_name] = 1.0;
|
||||
else
|
||||
{
|
||||
cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
if (!member_nodes.contains(node_name))
|
||||
member_nodes[node_name] = 1.0;
|
||||
else
|
||||
{
|
||||
cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -505,16 +511,16 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, const member
|
|||
operatingSystem);
|
||||
//! ADD CLUSTER
|
||||
else if (inCluster)
|
||||
if (minCpuNbr > 0 || maxCpuNbr > 0 || !userName.empty()
|
||||
|| !password.empty() || !remoteDrive.empty() || !remoteDirectory.empty()
|
||||
|| !programPath.empty() || !programConfig.empty()
|
||||
|| !matlabOctavePath.empty() || !operatingSystem.empty())
|
||||
{
|
||||
cerr << "Invalid option passed to [cluster]." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
if (name.empty() || clusters.contains(name))
|
||||
{
|
||||
if (minCpuNbr > 0 || maxCpuNbr > 0 || !userName.empty()
|
||||
|| !password.empty() || !remoteDrive.empty() || !remoteDirectory.empty()
|
||||
|| !programPath.empty() || !programConfig.empty()
|
||||
|| !matlabOctavePath.empty() || !operatingSystem.empty())
|
||||
{
|
||||
cerr << "Invalid option passed to [cluster]." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (name.empty() || clusters.contains(name))
|
||||
{
|
||||
cerr << "ERROR: The cluster must be assigned a unique name." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -525,6 +531,7 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, const member
|
|||
firstClusterName = name;
|
||||
clusters.emplace(name, member_nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -514,16 +514,17 @@ DynamicModel::parseIncludeExcludeEquations(const string &inc_exc_option_value, b
|
|||
{
|
||||
removeLeadingTrailingWhitespace(line);
|
||||
if (!line.empty())
|
||||
if (tags.empty() && line.find("=") != string::npos)
|
||||
{
|
||||
tagname_on_first_line = true;
|
||||
tags += line + "(";
|
||||
}
|
||||
else
|
||||
if (line.find("'") != string::npos)
|
||||
{
|
||||
if (tags.empty() && line.find("=") != string::npos)
|
||||
{
|
||||
tagname_on_first_line = true;
|
||||
tags += line + "(";
|
||||
}
|
||||
else if (line.find("'") != string::npos)
|
||||
tags += line + ",";
|
||||
else
|
||||
tags += "'" + line + "',";
|
||||
}
|
||||
}
|
||||
|
||||
if (!tags.empty())
|
||||
|
@ -634,21 +635,23 @@ DynamicModel::removeEquationsHelper(set<pair<string, string>> &listed_eqs_by_tag
|
|||
if (eqs_to_delete_by_number.contains(i))
|
||||
{
|
||||
if (excluded_vars_change_type)
|
||||
if (auto tmp = all_equation_tags.getTagValueByEqnAndKey(i, "endogenous"); tmp)
|
||||
excluded_vars.push_back(symbol_table.getID(*tmp));
|
||||
else
|
||||
{
|
||||
set<int> result;
|
||||
all_equations[i]->arg1->collectVariables(SymbolType::endogenous, result);
|
||||
if (result.size() == 1)
|
||||
excluded_vars.push_back(*result.begin());
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: Equation " << i+1
|
||||
<< " has been excluded but it does not have a single variable on its left-hand side or an `endogenous` tag" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (auto tmp = all_equation_tags.getTagValueByEqnAndKey(i, "endogenous"); tmp)
|
||||
excluded_vars.push_back(symbol_table.getID(*tmp));
|
||||
else
|
||||
{
|
||||
set<int> result;
|
||||
all_equations[i]->arg1->collectVariables(SymbolType::endogenous, result);
|
||||
if (result.size() == 1)
|
||||
excluded_vars.push_back(*result.begin());
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: Equation " << i+1
|
||||
<< " has been excluded but it does not have a single variable on its left-hand side or an `endogenous` tag" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2616,17 +2619,19 @@ DynamicModel::expandEqTags()
|
|||
set<int> existing_tags = equation_tags.getEqnsByKey("name");
|
||||
for (int eq = 0; eq < static_cast<int>(equations.size()); eq++)
|
||||
if (!existing_tags.contains(eq))
|
||||
if (auto lhs_expr = dynamic_cast<VariableNode *>(equations[eq]->arg1);
|
||||
lhs_expr
|
||||
&& !equation_tags.exists("name", symbol_table.getName(lhs_expr->symb_id)))
|
||||
equation_tags.add(eq, "name", symbol_table.getName(lhs_expr->symb_id));
|
||||
else if (!equation_tags.exists("name", to_string(eq+1)))
|
||||
equation_tags.add(eq, "name", to_string(eq+1));
|
||||
else
|
||||
{
|
||||
cerr << "Error creating default equation tag: cannot assign default tag to equation number " << eq+1 << " because it is already in use" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
if (auto lhs_expr = dynamic_cast<VariableNode *>(equations[eq]->arg1);
|
||||
lhs_expr
|
||||
&& !equation_tags.exists("name", symbol_table.getName(lhs_expr->symb_id)))
|
||||
equation_tags.add(eq, "name", symbol_table.getName(lhs_expr->symb_id));
|
||||
else if (!equation_tags.exists("name", to_string(eq+1)))
|
||||
equation_tags.add(eq, "name", to_string(eq+1));
|
||||
else
|
||||
{
|
||||
cerr << "Error creating default equation tag: cannot assign default tag to equation number " << eq+1 << " because it is already in use" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set<int>
|
||||
|
|
|
@ -5664,10 +5664,12 @@ BinaryOpNode::getPacNonOptimizingPart(int optim_share_symb_id) const
|
|||
expr_t non_optim_part = datatree.One;
|
||||
for (auto [factor, exponent] : factors)
|
||||
if (factor != one_minus_optim_share)
|
||||
if (exponent == 1)
|
||||
non_optim_part = datatree.AddTimes(non_optim_part, factor);
|
||||
else
|
||||
non_optim_part = datatree.AddDivide(non_optim_part, factor);
|
||||
{
|
||||
if (exponent == 1)
|
||||
non_optim_part = datatree.AddTimes(non_optim_part, factor);
|
||||
else
|
||||
non_optim_part = datatree.AddDivide(non_optim_part, factor);
|
||||
}
|
||||
|
||||
return non_optim_part;
|
||||
}
|
||||
|
|
|
@ -245,18 +245,20 @@ ModFile::checkPass(bool nostrict, bool stochastic)
|
|||
}
|
||||
|
||||
if (mod_file_struct.dsge_prior_weight_in_estimated_params)
|
||||
if (!mod_file_struct.dsge_var_estimated && !mod_file_struct.dsge_var_calibrated.empty())
|
||||
{
|
||||
cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, the prior weight cannot be calibrated "
|
||||
<< "via the dsge_var option in the estimation statement." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (!mod_file_struct.dsge_var_estimated && !symbol_table.exists("dsge_prior_weight"))
|
||||
{
|
||||
cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, it must either be declared as a parameter "
|
||||
{
|
||||
if (!mod_file_struct.dsge_var_estimated && !mod_file_struct.dsge_var_calibrated.empty())
|
||||
{
|
||||
cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, the prior weight cannot be calibrated "
|
||||
<< "via the dsge_var option in the estimation statement." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (!mod_file_struct.dsge_var_estimated && !symbol_table.exists("dsge_prior_weight"))
|
||||
{
|
||||
cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, it must either be declared as a parameter "
|
||||
<< "(deprecated) or the dsge_var option must be passed to the estimation statement (preferred)." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamic_model.staticOnlyEquationsNbr() != dynamic_model.dynamicOnlyEquationsNbr())
|
||||
{
|
||||
|
@ -477,13 +479,15 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
|
|||
PlannerObjectiveStatement *pos = nullptr;
|
||||
for (auto &statement : statements)
|
||||
if (auto pos2 = dynamic_cast<PlannerObjectiveStatement *>(statement.get()); pos2)
|
||||
if (pos)
|
||||
{
|
||||
cerr << "ERROR: there can only be one planner_objective statement" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
pos = pos2;
|
||||
{
|
||||
if (pos)
|
||||
{
|
||||
cerr << "ERROR: there can only be one planner_objective statement" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
pos = pos2;
|
||||
}
|
||||
assert(pos);
|
||||
const PlannerObjective &planner_objective = pos->getPlannerObjective();
|
||||
|
||||
|
@ -621,22 +625,23 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
|
|||
}
|
||||
|
||||
if (symbol_table.exists("dsge_prior_weight"))
|
||||
if (mod_file_struct.bayesian_irf_present)
|
||||
{
|
||||
if (symbol_table.exo_nbr() != symbol_table.observedVariablesNbr())
|
||||
{
|
||||
cerr << "ERROR: When estimating a DSGE-Var and the bayesian_irf option is passed to the estimation "
|
||||
<< "statement, the number of shocks must equal the number of observed variables." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (symbol_table.exo_nbr() < symbol_table.observedVariablesNbr())
|
||||
{
|
||||
if (mod_file_struct.bayesian_irf_present)
|
||||
{
|
||||
if (symbol_table.exo_nbr() != symbol_table.observedVariablesNbr())
|
||||
{
|
||||
cerr << "ERROR: When estimating a DSGE-Var and the bayesian_irf option is passed to the estimation "
|
||||
<< "statement, the number of shocks must equal the number of observed variables." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if (symbol_table.exo_nbr() < symbol_table.observedVariablesNbr())
|
||||
{
|
||||
cerr << "ERROR: When estimating a DSGE-Var, the number of shocks must be "
|
||||
<< "greater than or equal to the number of observed variables." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -728,10 +733,12 @@ ModFile::computingPass(bool no_tmp_terms, OutputType output, int params_derivs_o
|
|||
dynamic_model.computingPass(2, 0, global_eval_context, no_tmp_terms, block, use_dll);
|
||||
|
||||
if (linear)
|
||||
if (mod_file_struct.ramsey_model_present)
|
||||
orig_ramsey_dynamic_model.checkIsLinear();
|
||||
else
|
||||
dynamic_model.checkIsLinear();
|
||||
{
|
||||
if (mod_file_struct.ramsey_model_present)
|
||||
orig_ramsey_dynamic_model.checkIsLinear();
|
||||
else
|
||||
dynamic_model.checkIsLinear();
|
||||
}
|
||||
}
|
||||
|
||||
// Those matrices can only be filled here, because we use derivatives
|
||||
|
|
|
@ -845,13 +845,15 @@ ParsingDriver::end_model()
|
|||
|
||||
if (undeclared_model_variable_errors.size() > 0)
|
||||
for (auto &it : undeclared_model_variable_errors)
|
||||
if (nostrict)
|
||||
warning(it.second);
|
||||
else
|
||||
{
|
||||
exit_after_write = true;
|
||||
cerr << it.second << endl;
|
||||
}
|
||||
{
|
||||
if (nostrict)
|
||||
warning(it.second);
|
||||
else
|
||||
{
|
||||
exit_after_write = true;
|
||||
cerr << it.second << endl;
|
||||
}
|
||||
}
|
||||
undeclared_model_variable_errors.clear();
|
||||
|
||||
if (exit_after_write)
|
||||
|
@ -2154,13 +2156,15 @@ ParsingDriver::end_planner_objective(expr_t expr)
|
|||
bool exit_after_write = false;
|
||||
if (undeclared_model_variable_errors.size() > 0)
|
||||
for (auto &it : undeclared_model_variable_errors)
|
||||
if (nostrict)
|
||||
warning(it.second);
|
||||
else
|
||||
{
|
||||
exit_after_write = true;
|
||||
cerr << it.second << endl;
|
||||
}
|
||||
{
|
||||
if (nostrict)
|
||||
warning(it.second);
|
||||
else
|
||||
{
|
||||
exit_after_write = true;
|
||||
cerr << it.second << endl;
|
||||
}
|
||||
}
|
||||
undeclared_model_variable_errors.clear();
|
||||
if (exit_after_write)
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -3149,12 +3153,14 @@ ParsingDriver::add_model_var_or_external_function(const string &function_name, b
|
|||
error("Using a derivative of an external function (" + function_name + ") in the model block is currently not allowed.");
|
||||
|
||||
if (in_model_block || parsing_epilogue)
|
||||
if (mod_file->external_functions_table.getNargs(symb_id) == ExternalFunctionsTable::IDNotSet)
|
||||
error("Before using " + function_name
|
||||
+"() in the model block, you must first declare it via the external_function() statement");
|
||||
else if (static_cast<int>(stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id))
|
||||
error("The number of arguments passed to " + function_name
|
||||
+"() does not match those of a previous call or declaration of this function.");
|
||||
{
|
||||
if (mod_file->external_functions_table.getNargs(symb_id) == ExternalFunctionsTable::IDNotSet)
|
||||
error("Before using " + function_name
|
||||
+"() in the model block, you must first declare it via the external_function() statement");
|
||||
else if (static_cast<int>(stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id))
|
||||
error("The number of arguments passed to " + function_name
|
||||
+"() does not match those of a previous call or declaration of this function.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{ //First time encountering this external function i.e., not previously declared or encountered
|
||||
|
|
|
@ -686,10 +686,12 @@ SymbolTable::getOrigSymbIdForAuxVar(int aux_var_symb_id_arg) const noexcept(fals
|
|||
|| aux_var.type == AuxVarType::diffForward
|
||||
|| aux_var.type == AuxVarType::unaryOp)
|
||||
&& aux_var.symb_id == aux_var_symb_id_arg)
|
||||
if (optional<int> r = aux_var.orig_symb_id; r)
|
||||
return *r;
|
||||
else
|
||||
throw UnknownSymbolIDException(aux_var_symb_id_arg); // Some diff and unaryOp auxvars have orig_symb_id unset
|
||||
{
|
||||
if (optional<int> r = aux_var.orig_symb_id; r)
|
||||
return *r;
|
||||
else
|
||||
throw UnknownSymbolIDException(aux_var_symb_id_arg); // Some diff and unaryOp auxvars have orig_symb_id unset
|
||||
}
|
||||
throw UnknownSymbolIDException(aux_var_symb_id_arg);
|
||||
}
|
||||
|
||||
|
|
|
@ -1029,10 +1029,12 @@ Comprehension::eval(Environment &env) const
|
|||
throw;
|
||||
}
|
||||
if ((bp && *bp) || (dp && *dp))
|
||||
if (c_expr)
|
||||
values.emplace_back(c_expr->eval(env));
|
||||
else
|
||||
values.emplace_back(btp);
|
||||
{
|
||||
if (c_expr)
|
||||
values.emplace_back(c_expr->eval(env));
|
||||
else
|
||||
values.emplace_back(btp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return make_shared<Array>(values);
|
||||
|
|
Loading…
Reference in New Issue