Fix ticket #83 (cppcheck hangs) and add a test case for it
This commit is contained in:
parent
e71c6aaa9f
commit
798d86216a
|
@ -1261,7 +1261,7 @@ bool Tokenizer::simplifyConditions()
|
|||
Token::Match(tok->next(), "%num%") &&
|
||||
(tok2->str() == ")" || tok2->str() == "&&" || tok2->str() == "||"))
|
||||
{
|
||||
tok->next()->str();
|
||||
tok->next()->str((tok->next()->str() != "0") ? "true" : "false");
|
||||
ret = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ private:
|
|||
TEST_CASE(sizeof2);
|
||||
TEST_CASE(sizeof3);
|
||||
TEST_CASE(sizeof4);
|
||||
TEST_CASE(simplify_numeric_condition);
|
||||
}
|
||||
|
||||
|
||||
|
@ -939,6 +940,33 @@ private:
|
|||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS(std::string(" for ( int i = 0 ; i < 100 ; i + + ) { }"), ostr.str());
|
||||
}
|
||||
|
||||
void simplify_numeric_condition()
|
||||
{
|
||||
const char code[] =
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
"int x = 0;\n"
|
||||
"if( !x || 0 )\n"
|
||||
"{\n"
|
||||
"}\n"
|
||||
"}";
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
tokenizer.setVarId();
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS(std::string(" void f ( ) { int x ; x = 0 ; if ( ! x ) { } }"), ostr.str());
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue