Fix syntax error in issue 9155 (#1885)

This commit is contained in:
Paul Fultz II 2019-06-15 02:48:22 -05:00 committed by Daniel Marjamäki
parent 75720528b0
commit b466415bb4
2 changed files with 33 additions and 17 deletions

View File

@ -523,12 +523,15 @@ bool TemplateSimplifier::removeTemplate(Token *tok)
} }
else if (tok2->str() == "{") { else if (tok2->str() == "{") {
tok2 = tok2->link()->next(); tok2 = tok2->link();
if (indentlevel < 2) {
tok2 = tok2->next();
if (tok2 && tok2->str() == ";" && tok2->next()) if (tok2 && tok2->str() == ";" && tok2->next())
tok2 = tok2->next(); tok2 = tok2->next();
eraseTokens(tok, tok2); eraseTokens(tok, tok2);
deleteToken(tok); deleteToken(tok);
return true; return true;
}
} else if (tok2->str() == "}") { // garbage code! (#3449) } else if (tok2->str() == "}") { // garbage code! (#3449)
eraseTokens(tok,tok2); eraseTokens(tok,tok2);
deleteToken(tok); deleteToken(tok);
@ -1971,7 +1974,7 @@ void TemplateSimplifier::expandTemplate(
mTokenList.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->fileIndex()); mTokenList.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->fileIndex());
} }
brackets.pop(); brackets.pop();
if (brackets.empty()) { if (brackets.empty() && !Token::Match(tok3, "} >|,|%cop%")) {
inTemplateDefinition = false; inTemplateDefinition = false;
break; break;
} }

View File

@ -2684,6 +2684,7 @@ private:
} }
void template114() { // #9155 void template114() { // #9155
{
const char code[] = "template <typename a, a> struct b {};\n" const char code[] = "template <typename a, a> struct b {};\n"
"template <typename> struct c;\n" "template <typename> struct c;\n"
"template <typename> struct d : b<bool, std::is_polymorphic<int>{}> {};\n" "template <typename> struct d : b<bool, std::is_polymorphic<int>{}> {};\n"
@ -2696,6 +2697,18 @@ private:
"template < typename a > using f = typename e < c < d < a > > :: g > :: h ;"; "template < typename a > using f = typename e < c < d < a > > :: g > :: h ;";
ASSERT_EQUALS(exp, tok(code)); ASSERT_EQUALS(exp, tok(code));
} }
{
const char code[] = "template <typename a, a> struct b;\n"
"template <bool, typename> struct c;\n"
"template <typename a> struct d : b<bool, std::is_empty<a>{}> {};\n"
"template <typename a> using e = typename c<std::is_final<a>{}, d<a>>::f;\n";
const char exp[] = "template < typename a , a > struct b ; "
"template < bool , typename > struct c ; "
"struct d<a> ; "
"template < typename a > using e = typename c < std :: is_final < a > { } , d<a> > :: f ; struct d<a> : b < bool , std :: is_empty < a > { } > { } ;";
ASSERT_EQUALS(exp, tok(code));
}
}
void template115() { // #9153 void template115() { // #9153
const char code[] = "namespace {\n" const char code[] = "namespace {\n"