From a90c56ad767dabdc058013b349f583242038f3f3 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Thu, 6 Dec 2018 15:47:48 -0500 Subject: [PATCH] Fixed #8880 (Regression: syntax error for valid C++ template code) (#1509) --- lib/templatesimplifier.cpp | 10 ++++++++-- test/testsimplifytemplate.cpp | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 086c92f2e..70d5cce0f 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1047,8 +1047,14 @@ void TemplateSimplifier::expandTemplate( start = templateDeclarationToken->next(); end = templateDeclarationNameToken->linkAt(1)->next(); } - while (!Token::Match(end, ";|{|:")) + unsigned int typeindentlevel = 0; + while (!(typeindentlevel == 0 && Token::Match(end, ";|{|:"))) { + if (Token::Match(end, "<|(|{")) + ++typeindentlevel; + else if (Token::Match(end, ">|)|}")) + --typeindentlevel; end = end->next(); + } std::map links; while (start && start != end) { @@ -1057,7 +1063,7 @@ void TemplateSimplifier::expandTemplate( ++itype; if (itype < typeParametersInDeclaration.size()) { - unsigned int typeindentlevel = 0; + typeindentlevel = 0; for (const Token *typetok = mTypesUsedInTemplateInstantiation[itype]; typetok && (typeindentlevel > 0 || !Token::Match(typetok, ",|>")); typetok = typetok->next()) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 9f0482d48..289f98bb6 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -121,6 +121,7 @@ private: TEST_CASE(template81); TEST_CASE(template82); // 8603 TEST_CASE(template83); + TEST_CASE(template84); // #8880 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) @@ -1608,6 +1609,18 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template84() { // #8880 + const char code[] = "template \n" + "auto d() -> typename a::e {\n" + " d();\n" + "}"; + const char exp[] = "auto d ( ) . a < decltype ( int { } ) > :: e ; " + "auto d ( ) . a < decltype ( int { } ) > :: e { " + "d ( ) ; " + "}"; + 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"