From ab8e039a9a2f9d6fa7ac65053cd4dbb919277843 Mon Sep 17 00:00:00 2001 From: SunBlack Date: Wed, 20 Dec 2023 13:34:34 +0100 Subject: [PATCH] Fix several warnings raised by Cppcheck --- exprtk.hpp | 23 +-------------- exprtk_simple_example_05.cpp | 2 +- exprtk_simple_example_08.cpp | 2 +- exprtk_simple_example_09.cpp | 2 +- exprtk_simple_example_10.cpp | 2 +- exprtk_simple_example_17.cpp | 2 +- exprtk_test.cpp | 54 +++++++++++++++++------------------- 7 files changed, 32 insertions(+), 55 deletions(-) diff --git a/exprtk.hpp b/exprtk.hpp index b4530ba..98f5228 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -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 results_context_t; typedef typename results_context_t::type_store_t type_t; diff --git a/exprtk_simple_example_05.cpp b/exprtk_simple_example_05.cpp index fdbabc9..b8d113b 100644 --- a/exprtk_simple_example_05.cpp +++ b/exprtk_simple_example_05.cpp @@ -31,7 +31,7 @@ struct myfunc : public exprtk::ifunction : exprtk::ifunction(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); } diff --git a/exprtk_simple_example_08.cpp b/exprtk_simple_example_08.cpp index bfacb1e..04388ef 100644 --- a/exprtk_simple_example_08.cpp +++ b/exprtk_simple_example_08.cpp @@ -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(i), static_cast(error.token.position), exprtk::parser_error::to_str(error.mode).c_str(), diff --git a/exprtk_simple_example_09.cpp b/exprtk_simple_example_09.cpp index 8934523..64772ed 100644 --- a/exprtk_simple_example_09.cpp +++ b/exprtk_simple_example_09.cpp @@ -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(i), (result1 == T(1)) ? 'T' : 'F', (result2 == T(1)) ? 'T' : 'F', diff --git a/exprtk_simple_example_10.cpp b/exprtk_simple_example_10.cpp index 0a0add4..c15fa8e 100644 --- a/exprtk_simple_example_10.cpp +++ b/exprtk_simple_example_10.cpp @@ -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(i), result, std::sqrt(x)); diff --git a/exprtk_simple_example_17.cpp b/exprtk_simple_example_17.cpp index 24ae15b..c8ea444 100644 --- a/exprtk_simple_example_17.cpp +++ b/exprtk_simple_example_17.cpp @@ -32,7 +32,7 @@ struct rnd_01 : public exprtk::ifunction rnd_01() : exprtk::ifunction(0) { ::srand(static_cast(time(NULL))); } - inline T operator()() + inline T operator()() exprtk_override { // Note: Do not use this in production // Result is in the interval [0,1) diff --git a/exprtk_test.cpp b/exprtk_test.cpp index 65661d7..f65e57c 100644 --- a/exprtk_test.cpp +++ b/exprtk_test.cpp @@ -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(variable_list_size), static_cast(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(real_result), static_cast(result), @@ -3618,7 +3618,7 @@ struct myfunc : public exprtk::ifunction myfunc() : exprtk::ifunction(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 sine_deg() : exprtk::ifunction(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 cosine_deg() : exprtk::ifunction(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 typedef const T& type; base_func(const std::size_t& n) : exprtk::ifunction(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 struct test_func5 : public base_func { test_func5() : base_func(5){} }; @@ -5863,7 +5863,7 @@ struct va_func : public exprtk::ivararg_function exprtk::set_max_num_args(*this, 20); } - inline T operator()(const std::vector& arglist) + inline T operator()(const std::vector& arglist) exprtk_override { T result = T(0); @@ -6158,7 +6158,7 @@ struct overload_func : exprtk::igeneric_function 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(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(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(j), expression_str[j].c_str(), static_cast(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(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(j), expression_str[j].c_str(), static_cast(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(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(i), static_cast(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(j), expression_str[j].c_str(), static_cast(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(i), static_cast(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(j), expression_str[j].c_str(), static_cast(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(i)); return false; @@ -8682,7 +8680,7 @@ struct my_usr : public exprtk::parser::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') {