Fix specialized template regression. (#1425)
* Fix specialized template regression. Only check for instantiation of template being processed rather than count of all instantiations. * Add 2 more tests.
This commit is contained in:
parent
f72847530e
commit
290563b964
|
@ -1704,8 +1704,12 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
|||
}
|
||||
|
||||
// process uninstantiated templates
|
||||
const std::list<TokenAndName>::iterator it = std::find_if(mTemplateInstantiations.begin(),
|
||||
mTemplateInstantiations.end(),
|
||||
FindName(templateDeclaration.name));
|
||||
|
||||
// TODO: remove the specialized check and handle all uninstantiated templates someday.
|
||||
if (mTemplateInstantiations.empty() && specialized) {
|
||||
if (it == mTemplateInstantiations.end() && specialized) {
|
||||
simplifyCalculations();
|
||||
|
||||
Token * tok2 = const_cast<Token *>(tok->tokAt(namepos));
|
||||
|
|
|
@ -130,6 +130,7 @@ private:
|
|||
TEST_CASE(expandSpecialized1);
|
||||
TEST_CASE(expandSpecialized2);
|
||||
TEST_CASE(expandSpecialized3); // #8671
|
||||
TEST_CASE(expandSpecialized4);
|
||||
|
||||
TEST_CASE(templateAlias1);
|
||||
TEST_CASE(templateAlias2);
|
||||
|
@ -1818,6 +1819,58 @@ private:
|
|||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
|
||||
void expandSpecialized4() {
|
||||
{
|
||||
const char code[] = "template<> class C<char> { };\n"
|
||||
"map<int> m;";
|
||||
const char expected[] = "class C<char> { } ; "
|
||||
"map < int > m ;";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "template<> class C<char> { };\n"
|
||||
"map<int> m;\n"
|
||||
"C<char> c;";
|
||||
const char expected[] = "class C<char> { } ; "
|
||||
"map < int > m ; "
|
||||
"C<char> c ;";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "template<typename T> class C { };\n"
|
||||
"template<> class C<char> { };\n"
|
||||
"map<int> m;\n";
|
||||
const char expected[] = "template < typename T > class C { } ; "
|
||||
"class C<char> { } ; "
|
||||
"map < int > m ;";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "template<typename T> class C { };\n"
|
||||
"template<> class C<char> { };\n"
|
||||
"map<int> m;\n"
|
||||
"C<int> i;";
|
||||
const char expected[] = "class C<char> { } ; "
|
||||
"map < int > m ; "
|
||||
"C<int> i ; "
|
||||
"class C<int> { } ;";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "template<typename T> class C { };\n"
|
||||
"template<> class C<char> { };\n"
|
||||
"map<int> m;\n"
|
||||
"C<int> i;\n"
|
||||
"C<char> c;";
|
||||
const char expected[] = "class C<char> { } ; "
|
||||
"map < int > m ; "
|
||||
"C<int> i ; "
|
||||
"C<char> c ; "
|
||||
"class C<int> { } ;";
|
||||
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"
|
||||
|
|
Loading…
Reference in New Issue