Fix daca dnsdist crash (#2053)

This commit is contained in:
IOBYTE 2019-07-31 03:18:43 -04:00 committed by Daniel Marjamäki
parent e58e51ee14
commit 9436f72a94
2 changed files with 25 additions and 0 deletions

View File

@ -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());

View File

@ -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 <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
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 <typename TFunctionType, typename TType>\n"
" void registerFunction(TType fn) { }\n"
"};\n"
"void setupLuaBindingsDNSQuestion() {\n"
" g_lua.registerFunction<void (DNSQuestion ::*)(std ::string, std ::string)>();\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 <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"