Fix 10001: Syntax error on valid C++ code (#3697)

This commit is contained in:
Paul Fultz II 2022-01-12 15:04:28 -06:00 committed by GitHub
parent e4c8798974
commit fa651272f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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<std::string> 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();

View File

@ -6569,6 +6569,17 @@ private:
// #10139
ASSERT_NO_THROW(tokenizeAndStringify("template<typename F>\n"
"void foo(std::enable_if_t<value<F>>* = 0) {}\n"));
// #10001
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" int c;\n"
" template <class b> void d(b e) const { c < e ? c : e; }\n"
"};\n"));
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" int c;\n"
" template <class b> void d(b e) const { c > e ? c : e; }\n"
"};\n"));
}
void checkTemplates() {