From 020321769c5fb1f3955bf3531fd8e0979230be23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 14 Sep 2009 21:49:41 +0200 Subject: [PATCH] Fixed #658 (Assertion 'begin != __null' failed) --- src/tokenize.cpp | 7 ++++++- test/testsimplifytokens.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 1f8605484..7d4acd78b 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -718,12 +718,17 @@ void Tokenizer::simplifyTemplates() // Copy template.. int _indentlevel = 0; + int _parlevel = 0; for (const Token *tok3 = _tokens; tok3; tok3 = tok3->next()) { if (tok3->str() == "{") ++_indentlevel; else if (tok3->str() == "}") --_indentlevel; + else if (tok3->str() == "(") + ++_parlevel; + else if (tok3->str() == ")") + --_parlevel; // Start of template.. if (tok3 == tok) @@ -732,7 +737,7 @@ void Tokenizer::simplifyTemplates() } // member function implemented outside class definition - else if (_indentlevel == 0 && Token::Match(tok3, (pattern + " :: %var% (").c_str())) + else if (_indentlevel == 0 && _parlevel == 0 && Token::Match(tok3, (pattern + " :: %var% (").c_str())) { addtoken(name2.c_str(), tok3->linenr(), tok3->fileIndex()); while (tok3->str() != "::") diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 7071e3776..2588f1ea4 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -79,6 +79,7 @@ private: TEST_CASE(template10); TEST_CASE(template11); TEST_CASE(template12); + TEST_CASE(template13); TEST_CASE(template_default_parameter); TEST_CASE(template_typename); @@ -971,6 +972,33 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } + void template13() + { + const char code[] = "class BB {};\n" + "\n" + "template \n" + "class AA\n" + "{\n" + "public:\n" + " static AA create(T* newObject);\n" + "};\n" + "\n" + "class CC { public: CC(AA, int) {} };\n" + "\n" + "class XX {\n" + " AA y;\n" + "public:\n" + " XX();\n" + "};\n" + "\n" + "XX::XX():\n" + " y(AA::create(new CC(AA(), 0)))\n" + " {}\n"; + + // Just run it and check that there are not assertions. + sizeof_(code); + } + void template_default_parameter() { {