diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index fd5da6180..5749d7c55 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2134,7 +2134,7 @@ void TemplateSimplifier::expandTemplate( addNamespace(templateDeclaration, tok3); } mTokenList.addtoken(newName, tok3); - } else if (!Token::Match(tok3->next(), ":|{|=|;|[")) + } else if (!Token::Match(tok3->next(), ":|{|=|;|[|]")) tok3->str(newName); continue; } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 7e81eefa4..561ba9d56 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -256,6 +256,7 @@ private: TEST_CASE(expandSpecialized2); TEST_CASE(expandSpecialized3); // #8671 TEST_CASE(expandSpecialized4); + TEST_CASE(expandSpecialized5); // #10494 TEST_CASE(templateAlias1); TEST_CASE(templateAlias2); @@ -5591,6 +5592,27 @@ private: } } + void expandSpecialized5() { + const char code[] = "template class hash;\n" // #10494 + "template<> class hash {};\n" + "int f(int i) {\n" + " int hash = i;\n" + " const int a[2]{};\n" + " return a[hash];\n" + "}\n"; + + const char expected[] = "class hash ; " + "template < typename T > class hash ; " + "class hash { } ; " + "int f ( int i ) { " + "int hash ; hash = i ; " + "const int a [ 2 ] { } ; " + "return a [ hash ] ; " + "}"; + + ASSERT_EQUALS(expected, tok(code)); + } + void templateAlias1() { const char code[] = "template struct Foo {};\n" "template using Bar = Foo;\n"