Fix #784 (Tokenizer: Simplify 2[a] -> a[2])
http://sourceforge.net/apps/trac/cppcheck/ticket/784
This commit is contained in:
parent
23d8937661
commit
498beb7d9a
|
@ -1748,6 +1748,17 @@ void Tokenizer::simplifyTokenList()
|
|||
}
|
||||
}
|
||||
|
||||
// 0[a] -> a[0]
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, "%num% [ %var% ]"))
|
||||
{
|
||||
const std::string temp = tok->str();
|
||||
tok->str(tok->tokAt(2)->str());
|
||||
tok->tokAt(2)->str(temp);
|
||||
}
|
||||
}
|
||||
|
||||
simplifySizeof();
|
||||
|
||||
// Replace constants..
|
||||
|
|
|
@ -124,6 +124,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef3)
|
||||
TEST_CASE(simplifyTypedef4)
|
||||
TEST_CASE(simplifyTypedef5)
|
||||
TEST_CASE(reverseArraySyntax)
|
||||
}
|
||||
|
||||
std::string tok(const char code[], bool simplify = true)
|
||||
|
@ -1775,6 +1776,10 @@ private:
|
|||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
|
||||
void reverseArraySyntax()
|
||||
{
|
||||
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSimplifyTokens)
|
||||
|
|
Loading…
Reference in New Issue