From 45abd2d7fc2c71c0b49deb2dff28a7cce0329053 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Tue, 9 Feb 2010 00:16:12 +0200 Subject: [PATCH] Fix #1366 (void Tokenizer::simplifyTemplates() --> Abort) http://sourceforge.net/apps/trac/cppcheck/ticket/1366 --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a2958a0fb..407703096 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2866bdaa9..717c6882a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 \n" + "void fn2 (T t = []{return 1;}())\n" + "{}\n" + "int main()\n" + "{\n" + " fn2();\n" + "}\n"; + ASSERT_EQUALS(";\n\n\nint main ( )\n{\nfn2 ( ) ;\n}void fn2 ( int t = [ ] { return 1 ; } ( ) )\n{ }", tokenizeAndStringify(code)); + } }; REGISTER_TEST(TestTokenizer)