TemplateSimplifier: Fixed bad pattern that was detected by CheckInternal and pointed out by edward-san. The handling of recursive templates is better now.

This commit is contained in:
Daniel Marjamäki 2012-10-14 19:48:53 +02:00
parent 4995ab7828
commit be174d6266
2 changed files with 24 additions and 17 deletions

View File

@ -1039,7 +1039,7 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
}
if (tok3->str() == "<" && templateParameters(tok3) > 0)
++indentlevel;
else if (indentlevel > 0 && Token::simpleMatch(tok3, "> [,>]"))
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
--indentlevel;
templateMatchPattern += tok3->str();
templateMatchPattern += " ";
@ -1084,19 +1084,26 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
Token * tok5 = tok4->tokAt(2);
unsigned int typeCountInInstantion = 1U; // There is always atleast one type
const Token *typetok = (!typesUsedInTemplateInstantion.empty()) ? typesUsedInTemplateInstantion[0] : 0;
while (tok5 && tok5->str() != ">") {
if (tok5->str() != ",") {
if (!typetok ||
tok5->isUnsigned() != typetok->isUnsigned() ||
tok5->isSigned() != typetok->isSigned() ||
tok5->isLong() != typetok->isLong()) {
break;
}
unsigned int indentlevel5 = 0; // indentlevel for tok5
while (tok5 && (indentlevel5 > 0 || tok5->str() != ">")) {
if (tok5->str() == "<" && templateParameters(tok5) > 0)
++indentlevel5;
else if (indentlevel5 > 0 && Token::Match(tok5, "> [,>]"))
--indentlevel5;
else if (indentlevel5 == 0) {
if (tok5->str() != ",") {
if (!typetok ||
tok5->isUnsigned() != typetok->isUnsigned() ||
tok5->isSigned() != typetok->isSigned() ||
tok5->isLong() != typetok->isLong()) {
break;
}
typetok = typetok ? typetok->next() : 0;
} else {
typetok = (typeCountInInstantion < typesUsedInTemplateInstantion.size()) ? typesUsedInTemplateInstantion[typeCountInInstantion] : 0;
++typeCountInInstantion;
typetok = typetok ? typetok->next() : 0;
} else {
typetok = (typeCountInInstantion < typesUsedInTemplateInstantion.size()) ? typesUsedInTemplateInstantion[typeCountInInstantion] : 0;
++typeCountInInstantion;
}
}
tok5 = tok5->next();
}

View File

@ -2201,10 +2201,10 @@ private:
"template<class T> struct B { };\n"
"template<class T> struct C { A<B<X<T> > > ab; };\n"
"C<int> c;";
ASSERT_EQUALS("template < class T > struct A { } ; "
"template < class T > struct B { } ; "
"C<int> c ; "
"struct C<int> { A < B < X < int > > > ab ; }", tok(code));
ASSERT_EQUALS("C<int> c ; "
"struct C<int> { A<B<X<int>>> ab ; } "
"struct B<X<int>> { } " // <- redundant.. but nevermind
"struct A<B<X<int>>> { }", tok(code));
}
void template34() {