diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 7e2e84ff9..713cb7941 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -240,6 +240,9 @@ void TemplateSimplifier::removeTemplates(Token *tok) if (tok2->str() == "(") { tok2 = tok2->link(); + } else if (tok2->str() == ")") { // garbage code! (#3504) + Token::eraseTokens(tok,tok2); + tok->deleteThis(); } else if (tok2->str() == "{") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 872f3cfdd..31a0b0945 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -57,7 +57,8 @@ private: TEST_CASE(tokenize23); // tokenize "return - __LINE__;" // don't freak out when the syntax is wrong - TEST_CASE(wrong_syntax); + TEST_CASE(wrong_syntax1); + TEST_CASE(wrong_syntax2); TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO() TEST_CASE(minus); @@ -617,7 +618,7 @@ private: ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;")); } - void wrong_syntax() { + void wrong_syntax1() { { errout.str(""); const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"); @@ -648,6 +649,18 @@ private: } } + void wrong_syntax2() { // #3504 + const char code[] = "void f() {\n" + " X x;\n" + " Y y;\n" + "}\n" + "\n" + "void G( template class (j) ) {}"; + + // don't segfault.. + tokenizeAndStringify(code); + } + void wrong_syntax_if_macro() { // #2518 errout.str("");