From 53f514fc5cf16e3d06f2ba3d88775c8bf8f5d471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 29 Jan 2010 19:34:43 +0100 Subject: [PATCH] Tokenizer: Fixed const simplification --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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("");