From 4475c4c7e2f13f195f097840b51d987459d67a54 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Thu, 26 Sep 2019 04:31:19 -0400 Subject: [PATCH] template simplifier: fix syntax error (#2218) --- lib/templatesimplifier.cpp | 5 +---- lib/tokenize.cpp | 4 ++++ test/testsimplifytemplate.cpp | 11 +++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index d301c4d95..87706580e 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -419,7 +419,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) if (Token::Match(tok->previous(), "%var% <")) return 0; tok = tok->next(); - if (tok->str() == ">") + if (!tok || tok->str() == ">") return 0; unsigned int level = 0; @@ -3505,9 +3505,6 @@ void TemplateSimplifier::simplifyTemplates( } } - // split ">>" into "> >" - fixAngleBrackets(); - // Remove "typename" unless used in template arguments or using type alias.. for (Token *tok = mTokenList.front(); tok; tok = tok->next()) { if (Token::Match(tok, "typename %name%") && !Token::Match(tok->tokAt(-3), "using %name% =")) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d9c8e2ac1..a4104eb79 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4260,6 +4260,10 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Remove __asm.. simplifyAsm(); + // foo < bar < >> => foo < bar < > > + if (isCPP()) + mTemplateSimplifier->fixAngleBrackets(); + // Bail out if code is garbage if (mTimerResults) { Timer t("Tokenizer::tokenize::findGarbageCode", mSettings->showtime, mTimerResults); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 5ae0e2eec..38d95f357 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -185,6 +185,7 @@ private: TEST_CASE(template145); // syntax error TEST_CASE(template146); // syntax error TEST_CASE(template147); // syntax error + TEST_CASE(template148); // syntax error 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) @@ -3532,6 +3533,16 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template148() { // syntax error + const char code[] = "static_assert(var> == var> / 2\n" + " && var> == var>>>\n" + " && var> != 222, \"\");"; + const char exp[] = "static_assert ( var < S1 < 11 , 100 > > == var < S1 < 199 , 23 > > / 2 " + "&& var < S1 < 50 , 120 > > == var < S1 < 150 , var < S1 < 10 , 10 > > > > " + "&& var < S1 < 53 , 23 > > != 222 , \"\" ) ;"; + 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"