diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3ba3920d4..7a8408db0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6092,6 +6092,10 @@ bool Tokenizer::simplifyKnownVariables() if (pointeralias && Token::Match(tok3, ("!!= " + value).c_str())) break; + // Stop if do is found + if (tok3->str() == "do") + break; + // Stop if something like 'while (--var)' is found if (tok3->str() == "for" || tok3->str() == "while" || tok3->str() == "do") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2edf9dd71..142214609 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -120,6 +120,7 @@ private: TEST_CASE(simplifyKnownVariables31); TEST_CASE(simplifyKnownVariables32); // const TEST_CASE(simplifyKnownVariables33); // struct variable + TEST_CASE(simplifyKnownVariables34); TEST_CASE(simplifyKnownVariablesBailOutAssign); TEST_CASE(simplifyKnownVariablesBailOutFor1); TEST_CASE(simplifyKnownVariablesBailOutFor2); @@ -1852,6 +1853,21 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } + void simplifyKnownVariables34() + { + const char code[] = "void f() {\n" + " int x = 10;\n" + " do { cin >> x; } while (x > 5);\n" + " a[x] = 0;\n" + "}\n"; + const char expected[] = "void f ( ) {\n" + "int x ; x = 10 ;\n" + "do { cin >> x ; } while ( 5 < x ) ;\n" + "a [ x ] = 0 ;\n" + "}"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); + } + void simplifyKnownVariablesBailOutAssign() { const char code[] = "int foo() {\n"