From 9436f72a94b713905c0438871bfb786f338c8d86 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Wed, 31 Jul 2019 03:18:43 -0400 Subject: [PATCH] Fix daca dnsdist crash (#2053) --- lib/templatesimplifier.cpp | 4 ++++ test/testsimplifytemplate.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5b9d3a844..ad47886e2 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2834,6 +2834,10 @@ std::string TemplateSimplifier::getNewName( if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) { mTypesUsedInTemplateInstantiation.emplace_back(tok3, ""); } + if (tok3->str() == "(") + ++indentlevel; + else if (tok3->str() == ")") + --indentlevel; const bool constconst = tok3->str() == "const" && tok3->strAt(1) == "const"; if (!constconst) { typeStringsUsedInTemplateInstantiation.push_back(tok3->str()); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 544991859..dfb969b65 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -166,6 +166,7 @@ private: TEST_CASE(template126); // #9217 TEST_CASE(template127); // #9225 TEST_CASE(template128); // #9224 + TEST_CASE(template129); TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -3049,6 +3050,26 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template129() { + const char code[] = "class LuaContext {\n" + "public:\n" + " template \n" + " void registerFunction(TType fn) { }\n" + "};\n" + "void setupLuaBindingsDNSQuestion() {\n" + " g_lua.registerFunction();\n" + "}"; + const char exp[] = "class LuaContext { " + "public: " + "template < typename TFunctionType , typename TType > " + "void registerFunction ( TType fn ) { } " + "} ; " + "void setupLuaBindingsDNSQuestion ( ) { " + "g_lua . registerFunction < void ( DNSQuestion :: * ) ( std :: string , std :: string ) > ( ) ; " + "}"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"