Fix #10494 Same template name confuses check (#4011)

This commit is contained in:
chrchr-github 2022-04-13 12:25:21 +02:00 committed by GitHub
parent ea65fe2b63
commit 55cb396d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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;
}

View File

@ -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<typename T> class hash;\n" // #10494
"template<> class hash<int> {};\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<int> ; "
"template < typename T > class hash ; "
"class hash<int> { } ; "
"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<class T, int N> struct Foo {};\n"
"template<class T> using Bar = Foo<T,3>;\n"