Fix 10001: Syntax error on valid C++ code (#3697)
This commit is contained in:
parent
e4c8798974
commit
fa651272f0
|
@ -312,14 +312,15 @@ void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// template variable or type..
|
// template variable or type..
|
||||||
if (Token::Match(tok, "%type% <")) {
|
if (Token::Match(tok, "%type% <") && !Token::simpleMatch(tok, "template")) {
|
||||||
// these are used types..
|
// these are used types..
|
||||||
std::set<std::string> usedtypes;
|
std::set<std::string> usedtypes;
|
||||||
|
|
||||||
// parse this statement and see if the '<' and '>' are matching
|
// parse this statement and see if the '<' and '>' are matching
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
for (const Token *tok2 = tok; tok2 && !Token::simpleMatch(tok2, ";"); tok2 = tok2->next()) {
|
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;
|
break;
|
||||||
if (tok2->str() == "(")
|
if (tok2->str() == "(")
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
|
|
|
@ -6569,6 +6569,17 @@ private:
|
||||||
// #10139
|
// #10139
|
||||||
ASSERT_NO_THROW(tokenizeAndStringify("template<typename F>\n"
|
ASSERT_NO_THROW(tokenizeAndStringify("template<typename F>\n"
|
||||||
"void foo(std::enable_if_t<value<F>>* = 0) {}\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() {
|
void checkTemplates() {
|
||||||
|
|
Loading…
Reference in New Issue