diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4730622de..e9b464687 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10330,10 +10330,10 @@ void Tokenizer::simplifyMathExpressions() // pow(cosh(x),2)-pow(sinh(x),2) = -1 // @todo: sinh(x) * sinh(x) - cosh(x) * cosh(x) = -1 // cosh(x) * cosh(x) - sinh(x) * sinh(x) = -1 - if (Token::simpleMatch(tok, "pow (")) { - if (Token::simpleMatch(tok->tokAt(2), "sin (")) { + if (Token::Match(tok, "pow|powf|powl (")) { + if (Token::Match(tok->tokAt(2), "sin|sinf|sinl (")) { Token * const tok2 = tok->linkAt(3); - if (!Token::Match(tok2, ") , %num% ) + pow ( cos (")) + if (!Token::Match(tok2, ") , %num% ) + pow|powf|powl ( cos|cosf|cosl (")) continue; const std::string leftExponent = tok2->tokAt(2)->str(); if (!isTwoNumber(leftExponent)) @@ -10349,9 +10349,9 @@ void Tokenizer::simplifyMathExpressions() Token::eraseTokens(tok, tok3->link()->tokAt(4)); tok->str("1"); } - } else if (Token::simpleMatch(tok->tokAt(2), "cos (")) { + } else if (Token::Match(tok->tokAt(2), "cos|cosf|cosl (")) { Token * const tok2 = tok->linkAt(3); - if (!Token::Match(tok2, ") , %num% ) + pow ( sin (")) + if (!Token::Match(tok2, ") , %num% ) + pow|powf|powl ( sin|sinf|sinl (")) continue; const std::string leftExponent = tok2->tokAt(2)->str(); if (!isTwoNumber(leftExponent)) @@ -10367,9 +10367,9 @@ void Tokenizer::simplifyMathExpressions() Token::eraseTokens(tok, tok3->link()->tokAt(4)); tok->str("1"); } - } else if (Token::simpleMatch(tok->tokAt(2), "sinh (")) { + } else if (Token::Match(tok->tokAt(2), "sinh|sinhf|sinhl (")) { Token * const tok2 = tok->linkAt(3); - if (!Token::Match(tok2, ") , %num% ) - pow ( cosh (")) + if (!Token::Match(tok2, ") , %num% ) - pow|powf|powl ( cosh|coshf|coshl (")) continue; const std::string leftExponent = tok2->tokAt(2)->str(); if (!isTwoNumber(leftExponent)) @@ -10385,9 +10385,9 @@ void Tokenizer::simplifyMathExpressions() Token::eraseTokens(tok, tok3->link()->tokAt(4)); tok->str("-1"); } - } else if (Token::simpleMatch(tok->tokAt(2), "cosh (")) { + } else if (Token::Match(tok->tokAt(2), "cosh|coshf|coshl (")) { Token * const tok2 = tok->linkAt(3); - if (!Token::Match(tok2, ") , %num% ) - pow ( sinh (")) + if (!Token::Match(tok2, ") , %num% ) - pow|powf|powl ( sinh|sinhf|sinhl (")) continue; const std::string leftExponent = tok2->tokAt(2)->str(); if (!isTwoNumber(leftExponent)) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f5672c402..3a8ed7b4e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -9735,6 +9735,62 @@ private: "h = pow ( cosh ( x ) , 2.0 ) - pow ( sinh ( y ) , 2.0 ) ;\n" "}"; ASSERT_EQUALS(code2, tokenizeAndStringify(code2)); + + const char code3[] = "void foo() {\n" + " std::cout<