Fixed #36221 (Input streams: Wrong token list simplification)

This commit is contained in:
Daniel Marjamäki 2012-03-15 19:09:36 +01:00
parent 45759f6f7d
commit 555e8c6efc
2 changed files with 15 additions and 1 deletions

View File

@ -6504,7 +6504,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
const Token *prev = tok3->previous();
while (prev && prev->str() != "return" && (prev->isName() || prev->str() == "::"))
prev = prev->previous();
if (Token::Match(prev, "[;{}]"))
if (Token::Match(prev, ";|{|}|>>"))
break;
}

View File

@ -149,6 +149,7 @@ private:
TEST_CASE(simplifyKnownVariables44); // ticket #3117 - don't simplify static variables
TEST_CASE(simplifyKnownVariables45); // ticket #3281 - static constant variable not simplified
TEST_CASE(simplifyKnownVariables46); // ticket #3587 - >>
TEST_CASE(simplifyKnownVariables47); // ticket #3627 - >>
TEST_CASE(simplifyKnownVariablesIfEq); // if (a==5) => a is 5 in the block
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
TEST_CASE(simplifyKnownVariablesBailOutAssign2);
@ -2307,6 +2308,19 @@ private:
}
}
void simplifyKnownVariables47() {
// #3621
const char code[] = "void f() {\n"
" int x = 0;\n"
" cin >> std::hex >> x;\n"
"}";
const char expected[] = "void f ( ) {\n"
"int x ; x = 0 ;\n"
"cin >> std :: hex >> x ;\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.cpp"));
}
void simplifyKnownVariablesIfEq() {
const char code[] = "void f(int x) {\n"
" if (x==5) {\n"