Fixed #4544 (Crash with this line : class CD : public CC< class CB< CA > >)
This commit is contained in:
parent
e8fbd39efd
commit
9ad39ca4c0
|
@ -581,7 +581,16 @@ bool TemplateSimplifier::instantiateMatch(const Token *instance, const std::stri
|
|||
return false;
|
||||
|
||||
if (patternAfter) {
|
||||
const Token *tok = Token::findsimplematch(instance, ">");
|
||||
const Token *tok = instance;
|
||||
unsigned int indentlevel = 0;
|
||||
for (tok = instance; tok && (tok->str() != ">" || indentlevel > 0); tok = tok->next()) {
|
||||
if (Token::Match(tok, "[<,] %var% <") && templateParameters(tok->tokAt(2)) > 0)
|
||||
++indentlevel;
|
||||
if (indentlevel > 0 && tok->str() == ">")
|
||||
--indentlevel;
|
||||
if (indentlevel > 0 && tok->str() == ">>")
|
||||
indentlevel -= (indentlevel > 1) ? 2 : 1;
|
||||
}
|
||||
if (!tok || !Token::Match(tok->next(), patternAfter))
|
||||
return false;
|
||||
}
|
||||
|
@ -1087,11 +1096,19 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
|||
typeForNewNameStr.clear();
|
||||
break;
|
||||
}
|
||||
if (tok3->str() == "<" && templateParameters(tok3) > 0)
|
||||
if (Token::Match(tok3->tokAt(-2), "[<,] %var% <") && templateParameters(tok3) > 0)
|
||||
++indentlevel;
|
||||
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
|
||||
--indentlevel;
|
||||
templateMatchPattern += tok3->str();
|
||||
else if (indentlevel > 0 && tok3->str() == ">>") {
|
||||
if (indentlevel == 1) {
|
||||
templateMatchPattern += '>';
|
||||
typeForNewNameStr += '>';
|
||||
break;
|
||||
}
|
||||
indentlevel -= 2;
|
||||
}
|
||||
templateMatchPattern += (tok3->str() == ">>") ? std::string("> >") : tok3->str();
|
||||
templateMatchPattern += ' ';
|
||||
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
|
||||
typesUsedInTemplateInstantiation.push_back(tok3);
|
||||
|
|
|
@ -124,7 +124,7 @@ private:
|
|||
TEST_CASE(template30); // #3529 - template < template < ..
|
||||
TEST_CASE(template31); // #4010 - reference type
|
||||
TEST_CASE(template32); // #3818 - mismatching template not handled well
|
||||
TEST_CASE(template33); // #3818 - inner templates in template instantiation not handled well
|
||||
TEST_CASE(template33); // #3818,#4544 - inner templates in template instantiation not handled well
|
||||
TEST_CASE(template34); // #3706 - namespace => hang
|
||||
TEST_CASE(template35); // #4074 - A<'x'> a;
|
||||
TEST_CASE(template36); // #4310 - passing unknown template instantiation as template argument
|
||||
|
@ -2214,15 +2214,30 @@ private:
|
|||
}
|
||||
|
||||
void template33() {
|
||||
// #3818 - inner templates in template instantiation not handled well
|
||||
const char code[] = "template<class T> struct A { };\n"
|
||||
"template<class T> struct B { };\n"
|
||||
"template<class T> struct C { A<B<X<T> > > ab; };\n"
|
||||
"C<int> c;";
|
||||
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));
|
||||
{
|
||||
// #3818 - inner templates in template instantiation not handled well
|
||||
const char code[] = "template<class T> struct A { };\n"
|
||||
"template<class T> struct B { };\n"
|
||||
"template<class T> struct C { A<B<X<T> > > ab; };\n"
|
||||
"C<int> c;";
|
||||
ASSERT_EQUALS("C<int> c ; "
|
||||
"struct C<int> { A<B<X<int>>> ab ; } "
|
||||
"struct B<X<int>> { } " // <- redundant.. but nevermind
|
||||
"struct A<B<X<T>>> { } " // <- redundant.. but nevermind
|
||||
"struct A<B<X<int>>> { }", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
// #4544
|
||||
const char code[] = "struct A { };\n"
|
||||
"template<class T> struct B { };\n"
|
||||
"template<class T> struct C { };\n"
|
||||
"C< B<A> > c;";
|
||||
ASSERT_EQUALS("struct A { } ; "
|
||||
"template < class T > struct B { } ; " // <- redundant.. but nevermind
|
||||
"C<B<A>> c ; struct C<B<A>> { }",
|
||||
tok(code));
|
||||
}
|
||||
}
|
||||
|
||||
void template34() {
|
||||
|
|
Loading…
Reference in New Issue