Tokenizer: Fixed const simplification
This commit is contained in:
parent
c6263b51b5
commit
53f514fc5c
|
@ -5625,7 +5625,8 @@ void Tokenizer::simplifyConst()
|
|||
{
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, "[;{}(,] %type% const"))
|
||||
if (Token::Match(tok, "[;{}(,] %type% const") &&
|
||||
tok->next()->str().find(":") == std::string::npos)
|
||||
{
|
||||
tok->tokAt(2)->str(tok->tokAt(1)->str());
|
||||
tok->tokAt(1)->str("const");
|
||||
|
|
|
@ -42,6 +42,7 @@ private:
|
|||
TEST_CASE(tokenize1);
|
||||
TEST_CASE(tokenize2);
|
||||
TEST_CASE(tokenize3);
|
||||
TEST_CASE(tokenize4);
|
||||
|
||||
// don't freak out when the syntax is wrong
|
||||
TEST_CASE(wrong_syntax);
|
||||
|
@ -259,6 +260,22 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void tokenize4()
|
||||
{
|
||||
errout.str("");
|
||||
const std::string code("class foo\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" const int i;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("class foo\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
"const int i ;\n"
|
||||
"}", tokenizeAndStringify(code.c_str()));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void wrong_syntax()
|
||||
{
|
||||
errout.str("");
|
||||
|
|
Loading…
Reference in New Issue