Fixed ticket #377 (False positive with "char a[]")
Updated the tokenizer so "char a[]" is tokenized into "char *a"
This commit is contained in:
parent
db7b8fb3fd
commit
d8f95f68c3
|
@ -476,11 +476,23 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
|
|||
// replace "unsigned i" with "unsigned int i"
|
||||
unsignedint();
|
||||
|
||||
// Split up variable declarations.
|
||||
simplifyVarDecl();
|
||||
|
||||
// Handle templates..
|
||||
simplifyTemplates();
|
||||
|
||||
// change array to pointer..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, "%type% %var% [ ] [,;=]"))
|
||||
{
|
||||
tok->next()->deleteNext();
|
||||
tok->next()->deleteNext();
|
||||
tok->insertToken("*");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -66,6 +66,8 @@ private:
|
|||
TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )"
|
||||
TEST_CASE(declareVar);
|
||||
|
||||
TEST_CASE(declareArray);
|
||||
|
||||
TEST_CASE(dontRemoveIncrement);
|
||||
TEST_CASE(removePostIncrement);
|
||||
TEST_CASE(removePreIncrement);
|
||||
|
@ -385,6 +387,12 @@ private:
|
|||
ASSERT_EQUALS(code, tok(code));
|
||||
}
|
||||
|
||||
void declareArray()
|
||||
{
|
||||
const char code[] = "void f ( ) { char str [ ] = \"100\" ; } ";
|
||||
const char expected[] = "void f ( ) { char * str ; str = \"100\" ; } ";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
|
||||
void dontRemoveIncrement()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue