Fixed #1638 (Tokenizer::simplifyKnownVariables: removing variable declaration)
This commit is contained in:
parent
4014bd234f
commit
080374dc04
|
@ -2280,6 +2280,16 @@ void Tokenizer::setVarId()
|
|||
if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%"))
|
||||
continue;
|
||||
|
||||
// If pattern is "( %type% * %var% )" then check if it's a
|
||||
// variable declaration or a multiplication
|
||||
if (Token::Match(tok, "( %type% * %var% )") && !tok->next()->isStandardType())
|
||||
{
|
||||
if (!Token::Match(tok->previous(), "%type%"))
|
||||
continue;
|
||||
if (!Token::Match(tok->tokAt(5), "const|{|;"))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Token::Match(tok, "[,;{}(] %type%"))
|
||||
tok = tok->next();
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ private:
|
|||
TEST_CASE(varid13);
|
||||
TEST_CASE(varid14);
|
||||
TEST_CASE(varid15);
|
||||
TEST_CASE(varid16);
|
||||
TEST_CASE(varidStl);
|
||||
TEST_CASE(varid_delete);
|
||||
TEST_CASE(varid_functions);
|
||||
|
@ -1619,6 +1620,25 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void varid16()
|
||||
{
|
||||
const std::string code("void foo()\n"
|
||||
"{\n"
|
||||
" int x = 1;\n"
|
||||
" y = (z * x);\n"
|
||||
"}\n");
|
||||
|
||||
const std::string expected("\n\n##file 0\n"
|
||||
"1: void foo ( )\n"
|
||||
"2: {\n"
|
||||
"3: int x@1 ; x@1 = 1 ;\n"
|
||||
"4: y = ( z * x@1 ) ;\n"
|
||||
"5: }\n");
|
||||
|
||||
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
|
||||
}
|
||||
|
||||
|
||||
void varidStl()
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
|
|
Loading…
Reference in New Issue