From 877a233145a62ca7eb314945bbcf8bbd499afd79 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 16 Apr 2011 10:35:23 -0400 Subject: [PATCH] fix #2716 (Easy to reproduce crash) --- lib/tokenize.cpp | 16 ++++++++++++++++ test/testsimplifytokens.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1406816d5..d77c0a0d0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1476,6 +1476,22 @@ void Tokenizer::simplifyTypedef() } } + // check for entering a new namespace + else if (Token::Match(tok2, "namespace %any% {")) + { + if (spaceInfo[classLevel].isNamespace && + spaceInfo[classLevel].className == tok2->next()->str()) + { + classLevel++; + pattern.clear(); + for (std::size_t i = classLevel; i < spaceInfo.size(); i++) + pattern += (spaceInfo[i].className + " :: "); + + pattern += typeName->str(); + } + scope++; + } + // check for entering a new scope else if (tok2->str() == "{") { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 05419b35c..36748f60b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -254,6 +254,7 @@ private: TEST_CASE(simplifyTypedef88); // ticket #2675 TEST_CASE(simplifyTypedef89); // ticket #2717 TEST_CASE(simplifyTypedef90); // ticket #2718 + TEST_CASE(simplifyTypedef91); // ticket #2716 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -5112,6 +5113,32 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef91() // ticket #2716 + { + const char code[] = "namespace NS {\n" + " typedef int (*T)();\n" + " class A {\n" + " T f();\n" + " };\n" + "}\n" + "namespace NS {\n" + " T A::f() {}\n" + "}\n"; + const char expected[] = "namespace NS { " + "; " + "class A { " + "int ( * f ( ) ) ( ) ; " + "} ; " + "} " + "namespace NS { " + "int ( * A :: f ( ) ) ( ) { } " + "}"; + + checkSimplifyTypedef(code); + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {