Fixed #1909 (### Internal error in Cppcheck. Please report it)
This commit is contained in:
parent
289fa0e07f
commit
2e2baa23a6
|
@ -4962,10 +4962,10 @@ void Tokenizer::simplifyIfAssign()
|
||||||
|
|
||||||
// Delete paranthesis.. and remember how many there are with
|
// Delete paranthesis.. and remember how many there are with
|
||||||
// their links.
|
// their links.
|
||||||
std::list<Token *> braces;
|
std::stack<Token *> braces;
|
||||||
while (tok->next()->str() == "(")
|
while (tok->next()->str() == "(")
|
||||||
{
|
{
|
||||||
braces.push_back(tok->next()->link());
|
braces.push(tok->next()->link());
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4997,8 +4997,8 @@ void Tokenizer::simplifyIfAssign()
|
||||||
while (! braces.empty())
|
while (! braces.empty())
|
||||||
{
|
{
|
||||||
tok2->insertToken("(");
|
tok2->insertToken("(");
|
||||||
Token::createMutualLinks(tok2->next(), braces.back());
|
Token::createMutualLinks(tok2->next(), braces.top());
|
||||||
braces.pop_back();
|
braces.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNot)
|
if (isNot)
|
||||||
|
@ -5026,7 +5026,7 @@ void Tokenizer::simplifyIfAssign()
|
||||||
if (tok3 && indentlevel == 1)
|
if (tok3 && indentlevel == 1)
|
||||||
{
|
{
|
||||||
tok3 = tok3->previous();
|
tok3 = tok3->previous();
|
||||||
std::list<Token *> braces2;
|
std::stack<Token *> braces2;
|
||||||
|
|
||||||
for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous())
|
for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous())
|
||||||
{
|
{
|
||||||
|
@ -5037,23 +5037,14 @@ void Tokenizer::simplifyIfAssign()
|
||||||
newTok->linenr(tok2->linenr());
|
newTok->linenr(tok2->linenr());
|
||||||
|
|
||||||
// link() newly tokens manually
|
// link() newly tokens manually
|
||||||
if (newTok->str() == ")")
|
if (Token::Match(newTok, "}|)|]"))
|
||||||
{
|
{
|
||||||
braces.push_back(newTok);
|
braces2.push(newTok);
|
||||||
}
|
}
|
||||||
else if (newTok->str() == "]")
|
else if (Token::Match(newTok, "{|(|["))
|
||||||
{
|
{
|
||||||
braces2.push_back(newTok);
|
Token::createMutualLinks(newTok, braces2.top());
|
||||||
}
|
braces2.pop();
|
||||||
else if (newTok->str() == "(")
|
|
||||||
{
|
|
||||||
Token::createMutualLinks(newTok, braces.back());
|
|
||||||
braces.pop_back();
|
|
||||||
}
|
|
||||||
else if (newTok->str() == "[")
|
|
||||||
{
|
|
||||||
Token::createMutualLinks(newTok, braces2.back());
|
|
||||||
braces2.pop_back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,8 @@ private:
|
||||||
// Assignment in condition..
|
// Assignment in condition..
|
||||||
TEST_CASE(ifassign1);
|
TEST_CASE(ifassign1);
|
||||||
TEST_CASE(ifAssignWithCast);
|
TEST_CASE(ifAssignWithCast);
|
||||||
TEST_CASE(whileAssign);
|
TEST_CASE(whileAssign1);
|
||||||
|
TEST_CASE(whileAssign2);
|
||||||
|
|
||||||
// "if(0==x)" => "if(!x)"
|
// "if(0==x)" => "if(!x)"
|
||||||
TEST_CASE(ifnot);
|
TEST_CASE(ifnot);
|
||||||
|
@ -2087,7 +2088,7 @@ private:
|
||||||
ASSERT_EQUALS(exptected, tok(code));
|
ASSERT_EQUALS(exptected, tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
void whileAssign()
|
void whileAssign1()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS("; a = b ; while ( a ) { b = 0 ; a = b ; }", simplifyIfAssign(";while(a=b) { b = 0; }"));
|
ASSERT_EQUALS("; a = b ; while ( a ) { b = 0 ; a = b ; }", simplifyIfAssign(";while(a=b) { b = 0; }"));
|
||||||
ASSERT_EQUALS("; a . b = c ; while ( a . b ) { c = 0 ; a . b = c ; }", simplifyIfAssign(";while(a.b=c) { c=0; }"));
|
ASSERT_EQUALS("; a . b = c ; while ( a . b ) { c = 0 ; a . b = c ; }", simplifyIfAssign(";while(a.b=c) { c=0; }"));
|
||||||
|
@ -2102,6 +2103,20 @@ private:
|
||||||
tok("char *s; while (0 == (s=new char[10])) { }"));
|
tok("char *s; while (0 == (s=new char[10])) { }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void whileAssign2()
|
||||||
|
{
|
||||||
|
// #1909 - Internal error
|
||||||
|
errout.str("");
|
||||||
|
tok("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" int b;\n"
|
||||||
|
" while (b = sizeof (struct foo { int i0;}))\n"
|
||||||
|
" ;\n"
|
||||||
|
" if (!(0 <= b ))\n"
|
||||||
|
" ;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
std::string simplifyIfNot(const char code[])
|
std::string simplifyIfNot(const char code[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue