Fix several warnings raised by Cppcheck

This commit is contained in:
SunBlack 2023-12-20 13:34:34 +01:00
parent f46bffcd69
commit ab8e039a9a
7 changed files with 32 additions and 55 deletions

View File

@ -3735,27 +3735,6 @@ namespace exprtk
private:
bool modify(lexer::token& t)
{
if (lexer::token::e_symbol == t.type)
{
if (replace_map_.empty())
return false;
const replace_map_t::iterator itr = replace_map_.find(t.value);
if (replace_map_.end() != itr)
{
t.value = itr->second.first;
t.type = itr->second.second;
return true;
}
}
return false;
}
replace_map_t replace_map_;
};
@ -38661,7 +38640,7 @@ namespace exprtk
}
};
static T return_value(expression_t& e)
static T return_value(const expression_t& e)
{
typedef exprtk::results_context<T> results_context_t;
typedef typename results_context_t::type_store_t type_t;

View File

@ -31,7 +31,7 @@ struct myfunc : public exprtk::ifunction<T>
: exprtk::ifunction<T>(2)
{ exprtk::disable_has_side_effects(*this); }
inline T operator()(const T& v1, const T& v2)
inline T operator()(const T& v1, const T& v2) exprtk_override
{
return T(1) + (v1 * v2) / T(3);
}

View File

@ -67,7 +67,7 @@ void composite()
{
const error_t error = parser.get_error(i);
printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
printf("Error: %02u Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
static_cast<unsigned int>(i),
static_cast<unsigned int>(error.token.position),
exprtk::parser_error::to_str(error.mode).c_str(),

View File

@ -137,7 +137,7 @@ void primes()
const T result2 = expression2.value();
const T result3 = expression3.value();
printf("%03d Result1: %c Result2: %c Result3: %c\n",
printf("%03u Result1: %c Result2: %c Result3: %c\n",
static_cast<unsigned int>(i),
(result1 == T(1)) ? 'T' : 'F',
(result2 == T(1)) ? 'T' : 'F',

View File

@ -78,7 +78,7 @@ void newton_sqrt()
const T result = expression.value();
printf("sqrt(%03d) - Result: %15.13f\tReal: %15.13f\n",
printf("sqrt(%03u) - Result: %15.13f\tReal: %15.13f\n",
static_cast<unsigned int>(i),
result,
std::sqrt(x));

View File

@ -32,7 +32,7 @@ struct rnd_01 : public exprtk::ifunction<T>
rnd_01() : exprtk::ifunction<T>(0)
{ ::srand(static_cast<unsigned int>(time(NULL))); }
inline T operator()()
inline T operator()() exprtk_override
{
// Note: Do not use this in production
// Result is in the interval [0,1)

View File

@ -2912,7 +2912,7 @@ inline bool run_test03()
if (variable_list_size != total_symbol_count)
{
printf("run_test03() - Error - Invalid number of variables in symbol_table! Expected: %d got: %d\n",
printf("run_test03() - Error - Invalid number of variables in symbol_table! Expected: %u got: %u\n",
static_cast<unsigned int>(variable_list_size),
static_cast<unsigned int>(total_symbol_count));
@ -3256,7 +3256,7 @@ inline bool run_test05()
if (not_equal(result,real_result))
{
printf("run_test05() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\tIndex:%d\n",
printf("run_test05() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\tIndex:%u\n",
expression_string.c_str(),
static_cast<double>(real_result),
static_cast<double>(result),
@ -3618,7 +3618,7 @@ struct myfunc : public exprtk::ifunction<T>
myfunc() : exprtk::ifunction<T>(2) {}
inline T operator()(const T& v1, const T& v2)
inline T operator()(const T& v1, const T& v2) exprtk_override
{
return T(1) + (v1 * v2) / T(3);
}
@ -5181,7 +5181,7 @@ struct sine_deg : public exprtk::ifunction<T>
sine_deg() : exprtk::ifunction<T>(1) {}
inline T operator()(const T& v)
inline T operator()(const T& v) exprtk_override
{
return std::sin((v * T(exprtk::details::numeric::constant::pi)) / T(180));
}
@ -5194,7 +5194,7 @@ struct cosine_deg : public exprtk::ifunction<T>
cosine_deg() : exprtk::ifunction<T>(1) {}
inline T operator()(const T& v)
inline T operator()(const T& v) exprtk_override
{
return std::cos((v * T(exprtk::details::numeric::constant::pi)) / T(180));
}
@ -5582,12 +5582,12 @@ struct base_func : public exprtk::ifunction<T>
typedef const T& type;
base_func(const std::size_t& n) : exprtk::ifunction<T>(n) {}
inline T operator()(type v0, type v1, type v2, type v3, type v4) { return (v0 + v1 + v2 + v3 + v4); }
inline T operator()(type v0, type v1, type v2, type v3) { return (v0 + v1 + v2 + v3); }
inline T operator()(type v0, type v1, type v2) { return (v0 + v1 + v2); }
inline T operator()(type v0, type v1) { return (v0 + v1); }
inline T operator()(type v0) { return v0; }
inline T operator()() { return T(1.1234); }
inline T operator()(type v0, type v1, type v2, type v3, type v4) exprtk_override { return (v0 + v1 + v2 + v3 + v4); }
inline T operator()(type v0, type v1, type v2, type v3) exprtk_override { return (v0 + v1 + v2 + v3); }
inline T operator()(type v0, type v1, type v2) exprtk_override { return (v0 + v1 + v2); }
inline T operator()(type v0, type v1) exprtk_override { return (v0 + v1); }
inline T operator()(type v0) exprtk_override { return v0; }
inline T operator()() exprtk_override { return T(1.1234); }
};
template <typename T> struct test_func5 : public base_func<T> { test_func5() : base_func<T>(5){} };
@ -5863,7 +5863,7 @@ struct va_func : public exprtk::ivararg_function<T>
exprtk::set_max_num_args(*this, 20);
}
inline T operator()(const std::vector<T>& arglist)
inline T operator()(const std::vector<T>& arglist) exprtk_override
{
T result = T(0);
@ -6158,7 +6158,7 @@ struct overload_func : exprtk::igeneric_function<T>
for (std::size_t i = 0; i < parameters.size(); ++i)
{
generic_type& gt = parameters[i];
const generic_type& gt = parameters[i];
switch (gt.type)
{
@ -6984,9 +6984,7 @@ inline bool run_test18()
failure = true;
}
T sum = { T(0) };
sum = expression.value();
T sum = expression.value();
if (not_equal(sum,T(7)))
{
@ -8084,7 +8082,7 @@ inline bool run_test19()
if (!parser.compile(expression_str[i],expression))
{
printf("run_test19() - Error: %s Expression%d: %s\n",
printf("run_test19() - Error: %s Expression%u: %s\n",
parser.error().c_str(),
static_cast<unsigned int>(i),
expression_str[i].c_str());
@ -8142,12 +8140,12 @@ inline bool run_test19()
if (failure)
{
printf("run_test19() - Error in evaluation! (3) Results don't match! Prime: %d\n",
printf("run_test19() - Error in evaluation! (3) Results don't match! Prime: %u\n",
static_cast<unsigned int>(prime_list[i]));
for (std::size_t j = 0; j < expression_list.size(); ++j)
{
printf("Expression[%02d]: %s = %d\n",
printf("Expression[%02u]: %s = %u\n",
static_cast<unsigned int>(j),
expression_str[j].c_str(),
static_cast<unsigned int>(result[j]));
@ -8155,12 +8153,12 @@ inline bool run_test19()
}
else if (T(1) != expression_list[0].value())
{
printf("run_test19() - Error in evaluation! (4) Results don't match! Prime: %d\n",
printf("run_test19() - Error in evaluation! (4) Results don't match! Prime: %u\n",
static_cast<unsigned int>(prime_list[i]));
for (std::size_t j = 0; j < expression_list.size(); ++j)
{
printf("Expression[%02d]: %s = %d\n",
printf("Expression[%02u]: %s = %u\n",
static_cast<unsigned int>(j),
expression_str[j].c_str(),
static_cast<unsigned int>(result[j]));
@ -8286,7 +8284,7 @@ inline bool run_test19()
if (!parser.compile(expression_str[i],expression))
{
printf("run_test19() - Error: %s Expression[%02d]: %s\n",
printf("run_test19() - Error: %s Expression[%02u]: %s\n",
parser.error().c_str(),
static_cast<unsigned int>(i),
expression_str[i].c_str());
@ -8335,13 +8333,13 @@ inline bool run_test19()
if (failure)
{
printf("run_test19() - Error in evaluation! (5) Results don't match! fibonacci(%d) = %d\n",
printf("run_test19() - Error in evaluation! (5) Results don't match! fibonacci(%u) = %u\n",
static_cast<unsigned int>(i),
static_cast<unsigned int>(fibonacci_list[i]));
for (std::size_t j = 0; j < expression_list.size(); ++j)
{
printf("Expression[%02d]: %s = %d\n",
printf("Expression[%02u]: %s = %u\n",
static_cast<unsigned int>(j),
expression_str[j].c_str(),
static_cast<unsigned int>(result[j]));
@ -8349,13 +8347,13 @@ inline bool run_test19()
}
else if (fibonacci_list[i] != expression_list[0].value())
{
printf("run_test19() - Error in evaluation! (6) Results don't match! fibonacci(%d) = %d\n",
printf("run_test19() - Error in evaluation! (6) Results don't match! fibonacci(%u) = %u\n",
static_cast<unsigned int>(i),
static_cast<unsigned int>(fibonacci_list[i]));
for (std::size_t j = 0; j < expression_list.size(); ++j)
{
printf("Expression[%02d]: %s = %d\n",
printf("Expression[%02u]: %s = %u\n",
static_cast<unsigned int>(j),
expression_str[j].c_str(),
static_cast<unsigned int>(result[j]));
@ -8663,7 +8661,7 @@ inline bool run_test19()
if (T(1) != e[i].value())
{
printf("run_test19() - erf/erfc computation error %d",
printf("run_test19() - erf/erfc computation error %u",
static_cast<unsigned int>(i));
return false;
@ -8682,7 +8680,7 @@ struct my_usr : public exprtk::parser<T>::unknown_symbol_resolver
bool process(const std::string& unknown_symbol,
typename usr_t::usr_symbol_type& st,
T& default_value,
std::string& error_message)
std::string& error_message) exprtk_override
{
if (unknown_symbol[0] == 'v')
{