diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7b4dc00cf..13ce24d1c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8342,7 +8342,8 @@ bool Tokenizer::isTwoNumber(const std::string &s) // sqrtf(), sqrtl(), exp(), expf(), expl(), exp2(), // exp2f(), exp2l(), log2(), log2f(), log2l(), log1p(), // log1pf(), log1pl(), log10(), log10l(), log10f(), -// log(),logf(),logl(),logb(),logbf(),logbl() +// log(),logf(),logl(),logb(),logbf(),logbl(), acosh() +// acoshf(), acoshl() // in the tokenlist. // // Reference: @@ -8419,8 +8420,11 @@ bool Tokenizer::simplifyMathFunctions() tok->str("0"); // insert result into token list simplifcationMade = true; } - } else if (Token::Match(tok, "log2|log2f|log2l|log|logf|logl|log10|log10f|log10l|logb|logbf|logbl ( %num% )")) { - // Simplify: log2[f|l](1) = 0 + } else if (Token::Match(tok, "log2|log2f|log2l|log|logf|logl|log10|log10f|log10l|logb|logbf|logbl|acosh|acoshf|acoshl ( %num% )")) { + // Simplify: log2[f|l](1) = 0 , log10[f|l](1) = 0 + // log[f|l](1) = 0 , logb10[f|l](1) = 0 + // acosh[f|l](1) = 0 + // TODO: acos[f|l](1) = 0 // get number string const std::string parameter(tok->tokAt(2)->str()); // is parameter 1 ? diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b4d9e0bde..7a66cfc89 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -514,6 +514,7 @@ private: TEST_CASE(simplifyMathFunctions_isgreater); TEST_CASE(simplifyMathFunctions_fmin); TEST_CASE(simplifyMathFunctions_fmax); + TEST_CASE(simplifyMathFunctions_acosh); TEST_CASE(simplifyMathExpressions); //ticket #1620 @@ -8343,6 +8344,39 @@ private: ASSERT_EQUALS(false, Tokenizer::isTwoNumber("garbage")); } + void simplifyMathFunctions_acosh() { + // verify acosh(), acoshf(), acoshl() - simplifcation + const char code_acosh[] ="void f(int x) {\n" + " std::cout << acosh(x);\n" // do not simplify + " std::cout << acosh(1L);\n" // simplify to 0 + "}"; + const char expected_acosh[] = "void f ( int x ) {\n" + "std :: cout << acosh ( x ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_acosh, tokenizeAndStringify(code_acosh)); + + const char code_acoshf[] ="void f(float x) {\n" + " std::cout << acoshf(x);\n" // do not simplify + " std::cout << acoshf(1.0f);\n" // simplify to 0 + "}"; + const char expected_acoshf[] = "void f ( float x ) {\n" + "std :: cout << acoshf ( x ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_acoshf, tokenizeAndStringify(code_acoshf)); + + const char code_acoshl[] ="void f(long double x) {\n" + " std::cout << acoshl(x);\n" // do not simplify + " std::cout << acoshl(1.0d);\n" // simplify to 0 + "}"; + const char expected_acoshl[] = "void f ( long double x ) {\n" + "std :: cout << acoshl ( x ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_acoshl, tokenizeAndStringify(code_acoshl)); + } + void simplifyMathFunctions_sqrt() { // verify sqrt(), sqrtf(), sqrtl() - simplifcation const char code_sqrt[] ="void f(int x) {\n"