From fa651272f02a312d51f6be339a4d32b630d66049 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 12 Jan 2022 15:04:28 -0600 Subject: [PATCH] Fix 10001: Syntax error on valid C++ code (#3697) --- lib/templatesimplifier.cpp | 5 +++-- test/testtokenize.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5b10539e9..02a6bc79f 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -312,14 +312,15 @@ void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates() break; // template variable or type.. - if (Token::Match(tok, "%type% <")) { + if (Token::Match(tok, "%type% <") && !Token::simpleMatch(tok, "template")) { // these are used types.. std::set usedtypes; // parse this statement and see if the '<' and '>' are matching unsigned int level = 0; for (const Token *tok2 = tok; tok2 && !Token::simpleMatch(tok2, ";"); tok2 = tok2->next()) { - if (Token::simpleMatch(tok2, "{") && (!Token::Match(tok2->previous(), ">|%type%") || Token::simpleMatch(tok2->link(), "} ;"))) + if (Token::simpleMatch(tok2, "{") && + (!Token::Match(tok2->previous(), ">|%type%") || Token::simpleMatch(tok2->link(), "} ;"))) break; if (tok2->str() == "(") tok2 = tok2->link(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 09380a426..7308d292c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6569,6 +6569,17 @@ private: // #10139 ASSERT_NO_THROW(tokenizeAndStringify("template\n" "void foo(std::enable_if_t>* = 0) {}\n")); + + // #10001 + ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" + " int c;\n" + " template void d(b e) const { c < e ? c : e; }\n" + "};\n")); + + ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" + " int c;\n" + " template void d(b e) const { c > e ? c : e; }\n" + "};\n")); } void checkTemplates() {