diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 953f2dede..4065edc6e 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -372,7 +372,7 @@ void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates() // @todo add better expression detection if (!Token::Match(tok2->next(), "*| %type%|%num% ;")) inclevel = true; - } else if (tok2->next() && tok2->next()->isStandardType()) + } else if (tok2->next() && tok2->next()->isStandardType() && !Token::Match(tok2->tokAt(2), "(|{")) inclevel = true; else if (Token::simpleMatch(tok2, "< typename")) inclevel = true; @@ -1121,7 +1121,7 @@ void TemplateSimplifier::useDefaultArgumentValues(TokenAndName &declaration) (from->strAt(1) == ">" || (from->previous()->isName() && typeParameterNames.find(from->strAt(-1)) == typeParameterNames.end()))) ++indentlevel; - else if (from->str() == ">") + else if (from->str() == ">" && (links.empty() || links.top()->str() == "<")) --indentlevel; auto entry = typeParameterNames.find(from->str()); if (entry != typeParameterNames.end() && entry->second < instantiationArgs.size()) { @@ -2609,7 +2609,8 @@ bool TemplateSimplifier::simplifyCalculations(Token* frontToken, Token *backToke } if (validTokenEnd(bounded, tok, backToken, 2) && - Token::Match(tok, "char|short|int|long { }")) { + (Token::Match(tok, "char|short|int|long { }") || + Token::Match(tok, "char|short|int|long ( )"))) { tok->str("0"); // FIXME add type suffix tok->isSigned(false); tok->isUnsigned(false); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 631bf7982..1b5af432a 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -196,6 +196,7 @@ private: TEST_CASE(template154); // #9495 TEST_CASE(template155); // #9539 TEST_CASE(template156); + TEST_CASE(template157); // #9854 TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -3732,6 +3733,40 @@ private: tok(code); // don't crash } + void template157() { // #9854 + const char code[] = "template struct b1 { bool d = c; };\n" + "template struct b2 { bool d = c; };\n" + "template struct b3 { bool d = c; };\n" + "template struct b4 { bool d = c; };\n" + "template int())> struct b5 { bool d = c; };\n" + "template = int()> struct b6 { bool d = c; };\n" + "b1<0> var1;\n" + "b2<0> var2;\n" + "b3<0> var3;\n" + "b4<0> var4;\n" + "b5<0> var5;\n" + "b6<0> var6;"; + const char exp[] = "struct b1<0,true> ; " + "struct b2<0,false> ; " + "struct b3<0,false> ; " + "struct b4<0,true> ; " + "struct b5<0,false> ; " + "struct b6<0,true> ; " + "b1<0,true> var1 ; " + "b2<0,false> var2 ; " + "b3<0,false> var3 ; " + "b4<0,true> var4 ; " + "b5<0,false> var5 ; " + "b6<0,true> var6 ; " + "struct b6<0,true> { bool d ; d = true ; } ; " + "struct b5<0,false> { bool d ; d = false ; } ; " + "struct b4<0,true> { bool d ; d = true ; } ; " + "struct b3<0,false> { bool d ; d = false ; } ; " + "struct b2<0,false> { bool d ; d = false ; } ; " + "struct b1<0,true> { bool d ; d = true ; } ;"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"