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:
parent
4995ab7828
commit
be174d6266
|
@ -1039,7 +1039,7 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
|
||||||
}
|
}
|
||||||
if (tok3->str() == "<" && templateParameters(tok3) > 0)
|
if (tok3->str() == "<" && templateParameters(tok3) > 0)
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
else if (indentlevel > 0 && Token::simpleMatch(tok3, "> [,>]"))
|
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
templateMatchPattern += tok3->str();
|
templateMatchPattern += tok3->str();
|
||||||
templateMatchPattern += " ";
|
templateMatchPattern += " ";
|
||||||
|
@ -1084,7 +1084,13 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
|
||||||
Token * tok5 = tok4->tokAt(2);
|
Token * tok5 = tok4->tokAt(2);
|
||||||
unsigned int typeCountInInstantion = 1U; // There is always atleast one type
|
unsigned int typeCountInInstantion = 1U; // There is always atleast one type
|
||||||
const Token *typetok = (!typesUsedInTemplateInstantion.empty()) ? typesUsedInTemplateInstantion[0] : 0;
|
const Token *typetok = (!typesUsedInTemplateInstantion.empty()) ? typesUsedInTemplateInstantion[0] : 0;
|
||||||
while (tok5 && tok5->str() != ">") {
|
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 (tok5->str() != ",") {
|
||||||
if (!typetok ||
|
if (!typetok ||
|
||||||
tok5->isUnsigned() != typetok->isUnsigned() ||
|
tok5->isUnsigned() != typetok->isUnsigned() ||
|
||||||
|
@ -1098,6 +1104,7 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
|
||||||
typetok = (typeCountInInstantion < typesUsedInTemplateInstantion.size()) ? typesUsedInTemplateInstantion[typeCountInInstantion] : 0;
|
typetok = (typeCountInInstantion < typesUsedInTemplateInstantion.size()) ? typesUsedInTemplateInstantion[typeCountInInstantion] : 0;
|
||||||
++typeCountInInstantion;
|
++typeCountInInstantion;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tok5 = tok5->next();
|
tok5 = tok5->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2201,10 +2201,10 @@ private:
|
||||||
"template<class T> struct B { };\n"
|
"template<class T> struct B { };\n"
|
||||||
"template<class T> struct C { A<B<X<T> > > ab; };\n"
|
"template<class T> struct C { A<B<X<T> > > ab; };\n"
|
||||||
"C<int> c;";
|
"C<int> c;";
|
||||||
ASSERT_EQUALS("template < class T > struct A { } ; "
|
ASSERT_EQUALS("C<int> c ; "
|
||||||
"template < class T > struct B { } ; "
|
"struct C<int> { A<B<X<int>>> ab ; } "
|
||||||
"C<int> c ; "
|
"struct B<X<int>> { } " // <- redundant.. but nevermind
|
||||||
"struct C<int> { A < B < X < int > > > ab ; }", tok(code));
|
"struct A<B<X<int>>> { }", tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
void template34() {
|
void template34() {
|
||||||
|
|
Loading…
Reference in New Issue