diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4d02dfe57..3165b036e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3848,10 +3848,10 @@ bool Tokenizer::simplifyCalculations() } // (1-2) - if (Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% [],);=<>+-*/]") || - Token::Match(tok, "<< %num% [+-*/] %num% [],);=<>+-*/]") || - Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% <<") || - Token::Match(tok, "<< %num% [+-*/] %num% <<")) + while (Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% [],);=<>+-*/]") || + Token::Match(tok, "<< %num% [+-*/] %num% [],);=<>+-*/]") || + Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% <<") || + Token::Match(tok, "<< %num% [+-*/] %num% <<")) { tok = tok->next(); @@ -3877,7 +3877,7 @@ bool Tokenizer::simplifyCalculations() // instead of ((2 + 2) - (2 - 2)) = 4 if (Token::Match(tok->next(), "[+-*/]")) { - tok = tok->tokAt(-2); + tok = tok->previous(); continue; } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 0f885a9b7..3c7299cac 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -100,6 +100,7 @@ private: TEST_CASE(if_cond5); TEST_CASE(if_cond6); TEST_CASE(if_cond7); + TEST_CASE(if_cond8); TEST_CASE(if_or); @@ -836,6 +837,25 @@ private: } + void if_cond8() + { + const char filedata[] = "#if defined(A) + defined(B) + defined(C) != 1\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(1, actual.size()); + ASSERT_EQUALS("\n\n", actual[""]); + } + + + void if_or() { const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n"