Tokenizer::simplifyKnownVariables: Reduce debug-warnings for conditional increment

This commit is contained in:
Daniel Marjamäki 2010-11-21 13:40:42 +01:00
parent ec6edaee6e
commit 9d88e17c39
2 changed files with 19 additions and 0 deletions

View File

@ -6131,6 +6131,11 @@ bool Tokenizer::simplifyKnownVariables()
Token::Match(tok3->previous(), ", %var% ,|)"))
break;
// conditional increment
if (Token::Match(tok3->tokAt(-3), ") { ++|--") ||
Token::Match(tok3->tokAt(-2), ") { %var% ++|--"))
break;
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok3->linenr();

View File

@ -129,6 +129,7 @@ private:
TEST_CASE(simplifyKnownVariablesBailOutFor2);
TEST_CASE(simplifyKnownVariablesBailOutFor3);
TEST_CASE(simplifyKnownVariablesBailOutMemberFunction);
TEST_CASE(simplifyKnownVariablesBailOutConditionalIncrement);
TEST_CASE(varid1);
TEST_CASE(varid2);
@ -1961,6 +1962,19 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutConditionalIncrement()
{
const char code[] = "int f() {\n"
" int a = 0;\n"
" if (x) {\n"
" ++a;\n" // conditional increment
" }\n"
" return a;\n"
"}\n";
tokenizeAndStringify(code,true);
ASSERT_EQUALS("", errout.str()); // no debug warnings
}
std::string tokenizeDebugListing(const std::string &code, bool simplify = false)
{
Tokenizer tokenizer;