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)