Fixed #3691 (Tokenizer::simplifyKnownVariables: continue in switch)
This commit is contained in:
parent
2fbd77c5a1
commit
99a29eafc9
|
@ -5939,8 +5939,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
|||
if (Token::Match(tok3, "; %type% : ;"))
|
||||
break;
|
||||
|
||||
// Stop if return or break is found ..
|
||||
if (tok3->str() == "break")
|
||||
// Stop if break/continue is found ..
|
||||
if (tok3->str() == "break" || tok3->str() == "continue")
|
||||
break;
|
||||
if ((indentlevel3 > 1 || !Token::simpleMatch(Token::findsimplematch(tok3,";"), "; }")) && tok3->str() == "return")
|
||||
ret3 = true;
|
||||
|
|
|
@ -152,6 +152,7 @@ private:
|
|||
TEST_CASE(simplifyKnownVariables46); // ticket #3587 - >>
|
||||
TEST_CASE(simplifyKnownVariables47); // ticket #3627 - >>
|
||||
TEST_CASE(simplifyKnownVariables48); // ticket #3754 - wrong simplification in for loop header
|
||||
TEST_CASE(simplifyKnownVariables49); // #3691 - continue in switch
|
||||
TEST_CASE(simplifyKnownVariablesIfEq1); // if (a==5) => a is 5 in the block
|
||||
TEST_CASE(simplifyKnownVariablesIfEq2); // if (a==5) { buf[a++] = 0; }
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
||||
|
@ -2300,6 +2301,22 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyKnownVariables49() { // #3691
|
||||
const char code[] = "void f(int sz) {\n"
|
||||
" switch (x) {\n"
|
||||
" case 1: sz = 2; continue;\n"
|
||||
" case 2: x = sz; break;\n"
|
||||
" }\n"
|
||||
"}";
|
||||
const char expected[] = "void f ( int sz ) {\n"
|
||||
"switch ( x ) {\n"
|
||||
"case 1 : ; sz = 2 ; continue ;\n"
|
||||
"case 2 : ; x = sz ; break ;\n"
|
||||
"}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesIfEq1() {
|
||||
const char code[] = "void f(int x) {\n"
|
||||
" if (x==5) {\n"
|
||||
|
|
Loading…
Reference in New Issue