Skip to content

Commit fa65127

Browse files
authored
Fix 10001: Syntax error on valid C++ code (danmar#3697)
1 parent e4c8798 commit fa65127

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,15 @@ void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates()
312312
break;
313313

314314
// template variable or type..
315-
if (Token::Match(tok, "%type% <")) {
315+
if (Token::Match(tok, "%type% <") && !Token::simpleMatch(tok, "template")) {
316316
// these are used types..
317317
std::set<std::string> usedtypes;
318318

319319
// parse this statement and see if the '<' and '>' are matching
320320
unsigned int level = 0;
321321
for (const Token *tok2 = tok; tok2 && !Token::simpleMatch(tok2, ";"); tok2 = tok2->next()) {
322-
if (Token::simpleMatch(tok2, "{") && (!Token::Match(tok2->previous(), ">|%type%") || Token::simpleMatch(tok2->link(), "} ;")))
322+
if (Token::simpleMatch(tok2, "{") &&
323+
(!Token::Match(tok2->previous(), ">|%type%") || Token::simpleMatch(tok2->link(), "} ;")))
323324
break;
324325
if (tok2->str() == "(")
325326
tok2 = tok2->link();

test/testtokenize.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,6 +6569,17 @@ class TestTokenizer : public TestFixture {
65696569
// #10139
65706570
ASSERT_NO_THROW(tokenizeAndStringify("template<typename F>\n"
65716571
"void foo(std::enable_if_t<value<F>>* = 0) {}\n"));
6572+
6573+
// #10001
6574+
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
6575+
" int c;\n"
6576+
" template <class b> void d(b e) const { c < e ? c : e; }\n"
6577+
"};\n"));
6578+
6579+
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
6580+
" int c;\n"
6581+
" template <class b> void d(b e) const { c > e ? c : e; }\n"
6582+
"};\n"));
65726583
}
65736584

65746585
void checkTemplates() {

0 commit comments

Comments
 (0)