Fixed #36221 (Input streams: Wrong token list simplification)
This commit is contained in:
parent
45759f6f7d
commit
555e8c6efc
|
@ -6504,7 +6504,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
const Token *prev = tok3->previous();
|
const Token *prev = tok3->previous();
|
||||||
while (prev && prev->str() != "return" && (prev->isName() || prev->str() == "::"))
|
while (prev && prev->str() != "return" && (prev->isName() || prev->str() == "::"))
|
||||||
prev = prev->previous();
|
prev = prev->previous();
|
||||||
if (Token::Match(prev, "[;{}]"))
|
if (Token::Match(prev, ";|{|}|>>"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,7 @@ private:
|
||||||
TEST_CASE(simplifyKnownVariables44); // ticket #3117 - don't simplify static variables
|
TEST_CASE(simplifyKnownVariables44); // ticket #3117 - don't simplify static variables
|
||||||
TEST_CASE(simplifyKnownVariables45); // ticket #3281 - static constant variable not simplified
|
TEST_CASE(simplifyKnownVariables45); // ticket #3281 - static constant variable not simplified
|
||||||
TEST_CASE(simplifyKnownVariables46); // ticket #3587 - >>
|
TEST_CASE(simplifyKnownVariables46); // ticket #3587 - >>
|
||||||
|
TEST_CASE(simplifyKnownVariables47); // ticket #3627 - >>
|
||||||
TEST_CASE(simplifyKnownVariablesIfEq); // if (a==5) => a is 5 in the block
|
TEST_CASE(simplifyKnownVariablesIfEq); // if (a==5) => a is 5 in the block
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutAssign2);
|
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() {
|
void simplifyKnownVariablesIfEq() {
|
||||||
const char code[] = "void f(int x) {\n"
|
const char code[] = "void f(int x) {\n"
|
||||||
" if (x==5) {\n"
|
" if (x==5) {\n"
|
||||||
|
|
Loading…
Reference in New Issue