Fix issue 9156: Analysis failed because square brackets arent linked correctly (#1871)

This commit is contained in:
Paul Fultz II 2019-06-09 01:10:57 -05:00 committed by Daniel Marjamäki
parent 7a87786cbc
commit 1f24aa778b
2 changed files with 32 additions and 7 deletions

View File

@ -1578,9 +1578,7 @@ void TemplateSimplifier::expandTemplate(
previous->isSigned(typetok->isSigned());
previous->isUnsigned(typetok->isUnsigned());
previous->isLong(typetok->isLong());
if (previous->str() == "{") {
brackets1.push(previous);
} else if (previous->str() == "(") {
if (Token::Match(previous, "{|(|[")) {
brackets1.push(previous);
} else if (previous->str() == "}") {
assert(brackets1.empty() == false);
@ -1592,6 +1590,11 @@ void TemplateSimplifier::expandTemplate(
assert(brackets1.top()->str() == "(");
Token::createMutualLinks(brackets1.top(), previous);
brackets1.pop();
} else if (previous->str() == "]") {
assert(brackets1.empty() == false);
assert(brackets1.top()->str() == "[");
Token::createMutualLinks(brackets1.top(), previous);
brackets1.pop();
}
}
} else {
@ -1785,9 +1788,7 @@ void TemplateSimplifier::expandTemplate(
--typeindentlevel;
mTokenList.addtoken(typetok, tok5->linenr(), tok5->fileIndex());
Token *back = mTokenList.back();
if (back->str() == "{") {
brackets1.push(back);
} else if (back->str() == "(") {
if (Token::Match(back, "{|(|[")) {
brackets1.push(back);
} else if (back->str() == "}") {
assert(brackets1.empty() == false);
@ -1799,6 +1800,11 @@ void TemplateSimplifier::expandTemplate(
assert(brackets1.top()->str() == "(");
Token::createMutualLinks(brackets1.top(), back);
brackets1.pop();
} else if (back->str() == "]") {
assert(brackets1.empty() == false);
assert(brackets1.top()->str() == "[");
Token::createMutualLinks(brackets1.top(), back);
brackets1.pop();
}
back->isTemplateArg(true);
added = true;
@ -1863,7 +1869,7 @@ void TemplateSimplifier::expandTemplate(
if (copy) {
mTokenList.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
Token *back = mTokenList.back();
if (back->str() == "{") {
if (Token::Match(back, "{|(|[")) {
brackets1.push(back);
} else if (back->str() == "(") {
brackets1.push(back);
@ -1877,6 +1883,11 @@ void TemplateSimplifier::expandTemplate(
assert(brackets1.top()->str() == "(");
Token::createMutualLinks(brackets1.top(), back);
brackets1.pop();
} else if (back->str() == "]") {
assert(brackets1.empty() == false);
assert(brackets1.top()->str() == "[");
Token::createMutualLinks(brackets1.top(), back);
brackets1.pop();
}
back->isTemplateArg(true);
}

View File

@ -7784,6 +7784,20 @@ private:
"template <template <class> class t, class... w, template <class> class x,\n"
" class... u>\n"
"struct s<t<w...>, x<u...>>;\n"))
// #9156
ASSERT_NO_THROW(tokenizeAndStringify(
"template <typename> struct a;\n"
"template <bool> struct b;\n"
"template <class k, class> using d = typename b<k::c>::e;\n"
"template <class> struct f;\n"
"template <template <class> class, class... g> using i = typename f<g...>::e;\n"
"template <template <class> class h, class... g> using ab = d<i<h, g...>, int>;\n"
"template <template <class> class h, class... g> struct j {\n"
" template <class... ag> using ah = typename ab<h, ag..., g...>::e;\n"
"};\n"
"template <class> struct F;\n"
"int main() { using T = void (*)(a<j<F, char[]>>); }\n"))
}
void noCrash1() {