Fix #1366 (void Tokenizer::simplifyTemplates() --> Abort)

http://sourceforge.net/apps/trac/cppcheck/ticket/1366
This commit is contained in:
Reijo Tomperi 2010-02-09 00:16:12 +02:00
parent 8853f304af
commit 45abd2d7fc
2 changed files with 14 additions and 1 deletions

View File

@ -1560,7 +1560,7 @@ void Tokenizer::simplifyTemplates()
else if (tok3->str() == "}")
{
if (indentlevel <= 1)
if (indentlevel <= 1 && brackets.empty() && brackets2.empty())
{
// there is a bug if indentlevel is 0
// the "}" token should only be added if indentlevel is 1 but I add it always intentionally

View File

@ -192,6 +192,7 @@ private:
TEST_CASE(removeRedundantAssignment);
TEST_CASE(removedeclspec);
TEST_CASE(cpp0xtemplate);
}
@ -3004,6 +3005,18 @@ private:
{
ASSERT_EQUALS("a b", tokenizeAndStringify("a __declspec ( dllexport ) b"));
}
void cpp0xtemplate()
{
const char *code = "template <class T>\n"
"void fn2 (T t = []{return 1;}())\n"
"{}\n"
"int main()\n"
"{\n"
" fn2<int>();\n"
"}\n";
ASSERT_EQUALS(";\n\n\nint main ( )\n{\nfn2<int> ( ) ;\n}void fn2<int> ( int t = [ ] { return 1 ; } ( ) )\n{ }", tokenizeAndStringify(code));
}
};
REGISTER_TEST(TestTokenizer)