Fixed #658 (Assertion 'begin != __null' failed)

This commit is contained in:
Daniel Marjamäki 2009-09-14 21:49:41 +02:00
parent 2b6955dde5
commit 020321769c
2 changed files with 34 additions and 1 deletions

View File

@ -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() != "::")

View File

@ -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 <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()
{
{