Tokenize: Fixed bug in Tokenize::simplifyKnownVariables

This commit is contained in:
Daniel Marjamäki 2010-10-10 19:27:42 +02:00
parent f427fdb856
commit 81aed3fbd7
3 changed files with 16 additions and 26 deletions

View File

@ -5855,19 +5855,6 @@ bool Tokenizer::simplifyKnownVariables()
}
}
}
if (tok3->next()->varId() == varid)
{
tok3->next()->str(value);
tok3->next()->varId(valueVarId);
ret = true;
}
else if (tok3->tokAt(3)->varId() == varid)
{
tok3->tokAt(3)->str(value);
tok3->tokAt(3)->varId(valueVarId);
ret = true;
}
}
if (indentlevel == indentlevel3 && Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value))

View File

@ -98,7 +98,6 @@ private:
TEST_CASE(missingInnerComparison1);
TEST_CASE(missingInnerComparison2); // no FP when there is comparison
TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing
TEST_CASE(missingInnerComparison4); // no FP when the iterator is incremented in inner for loop
}
void check(const std::string &code)
@ -1081,18 +1080,6 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
void missingInnerComparison4()
{
check("void f(std::list<int> &ints) {\n"
" for (std::list<int>::iterator it1 = ints.begin(); it1 != ints.end(); ++it1) {\n"
" std::list<int>::iterator it2 = it1;\n"
" for (++it2; it2 != ints.end(); ++it2)\n"
" { }\n"
" }\n"
"}\n");
TODO_ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestStl)

View File

@ -118,6 +118,7 @@ private:
TEST_CASE(simplifyKnownVariables27);
TEST_CASE(simplifyKnownVariables28);
TEST_CASE(simplifyKnownVariables29); // ticket #1811
TEST_CASE(simplifyKnownVariables30);
TEST_CASE(varid1);
TEST_CASE(varid2);
@ -1785,6 +1786,21 @@ private:
}
}
void simplifyKnownVariables30()
{
const char code[] = "int foo() {\n"
" iterator it1 = ints.begin();\n"
" iterator it2 = it1;\n"
" for (++it2;it2!=ints.end();++it2);\n"
"}\n";
const char expected[] = "int foo ( ) {\n"
"iterator it1 ; it1 = ints . begin ( ) ;\n"
"iterator it2 ; it2 = it1 ;\n"
"for ( ++ it2 ; it2 != ints . end ( ) ; ++ it2 ) { ; }\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
std::string tokenizeDebugListing(const std::string &code, bool simplify = false)
{
Tokenizer tokenizer;