diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 26a4359ac..e8f6c61d4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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"); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 547566aab..ce76d39ca 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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("");