Skip to content

Commit

Permalink
Fixed #658 (Assertion 'begin != __null' failed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Marjamäki committed Sep 14, 2009
1 parent 2b6955d commit 0203217
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() != "::")
Expand Down
28 changes: 28 additions & 0 deletions test/testsimplifytokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class TestSimplifyTokens : public TestFixture
TEST_CASE(template10);
TEST_CASE(template11);
TEST_CASE(template12);
TEST_CASE(template13);
TEST_CASE(template_default_parameter);
TEST_CASE(template_typename);

Expand Down Expand Up @@ -971,6 +972,33 @@ class TestSimplifyTokens : public TestFixture
ASSERT_EQUALS(expected, sizeof_(code));
}

void template13()
{
const char code[] = "class BB {};\n"
"\n"
"template <class T>\n"
"class AA\n"
"{\n"
"public:\n"
" static AA<T> create(T* newObject);\n"
"};\n"
"\n"
"class CC { public: CC(AA<BB>, int) {} };\n"
"\n"
"class XX {\n"
" AA<CC> y;\n"
"public:\n"
" XX();\n"
"};\n"
"\n"
"XX::XX():\n"
" y(AA<CC>::create(new CC(AA<BB>(), 0)))\n"
" {}\n";

// Just run it and check that there are not assertions.
sizeof_(code);
}

void template_default_parameter()
{
{
Expand Down

0 comments on commit 0203217

Please sign in to comment.