diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0762ca5bb..0b08eaff1 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2141,7 +2141,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 48508f45e..2eee9fd88 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -5561,6 +5561,24 @@ private: "class C { } ;"; ASSERT_EQUALS(expected, tok(code)); } + { + const char code[] = "class A {};\n" + "template struct B;\n" + "template<> struct B {};\n" + "int f() {\n" + " int B[1] = {};\n" + " return B[0];\n" + "}\n"; + const char expected[] = "class A { } ; " + "struct B ; " + "template < typename T > struct B ; " + "struct B { } ; " + "int f ( ) { " + "int B [ 1 ] = { } ; " + "return B [ 0 ] ; " + "}"; + ASSERT_EQUALS(expected, tok(code)); + } } void templateAlias1() { diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 1242d250f..04bafb81b 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -5781,6 +5781,17 @@ private: " std::array a;\n" "}\n"); ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: a\n", errout.str()); + + functionVariableUsage("class A {};\n" // #9471 + " namespace std {\n" + " template<>\n" + " struct hash {};\n" + "}\n" + "char f() {\n" + " std::string hash = \"-\";\n" + " return hash[0];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void localvarFuncPtr() {