Tokenizer::simplifyKnownVariables: Reduce debug-warnings for conditional increment
This commit is contained in:
parent
ec6edaee6e
commit
9d88e17c39
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue