Fix synax error in issue 9057 and 9138 (#1843)
This commit is contained in:
parent
29e5992e51
commit
9055682fdc
|
@ -3845,8 +3845,15 @@ void Tokenizer::createLinks2()
|
|||
continue;
|
||||
}
|
||||
|
||||
while (!type.empty() && type.top()->str() == "<")
|
||||
while (!type.empty() && type.top()->str() == "<") {
|
||||
const Token* end = type.top()->findClosingBracket();
|
||||
if (Token::Match(end, "> ;|>"))
|
||||
break;
|
||||
// Variable declaration
|
||||
if (Token::Match(end, "> %var% ;") && (type.top()->tokAt(-2) == nullptr || Token::Match(type.top()->tokAt(-2), ";|}|{")))
|
||||
break;
|
||||
type.pop();
|
||||
}
|
||||
} else if (token->str() == "<" &&
|
||||
((token->previous() && token->previous()->isName() && !token->previous()->varId()) ||
|
||||
Token::Match(token->next(), ">|>>"))) {
|
||||
|
|
|
@ -4593,6 +4593,30 @@ private:
|
|||
ASSERT_EQUALS(true, tok->linkAt(3) == nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
// bool f = a < b || c > d
|
||||
const char code[] = "bool f = a < b || c > d;";
|
||||
errout.str("");
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
const Token *tok = tokenizer.tokens();
|
||||
|
||||
ASSERT_EQUALS(true, tok->linkAt(4) == nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
// template
|
||||
const char code[] = "a < b || c > d;";
|
||||
errout.str("");
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
const Token *tok = tokenizer.tokens();
|
||||
|
||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(5));
|
||||
}
|
||||
|
||||
{
|
||||
// if (a < ... > d) { }
|
||||
const char code[] = "if (a < b || c == 3 || d > e);";
|
||||
|
@ -4820,6 +4844,20 @@ private:
|
|||
tokenizer.tokenize(istr, "test.cpp");
|
||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link());
|
||||
}
|
||||
|
||||
{
|
||||
// #9057
|
||||
const char code[] = "template <bool> struct a;\n"
|
||||
"template <bool b, typename> using c = typename a<b>::d;\n"
|
||||
"template <typename e> using f = c<e() && sizeof(int), int>;\n"
|
||||
"template <typename e, typename = f<e>> struct g {};\n"
|
||||
"template <typename e> using baz = g<e>;\n";
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> > ;")->link());
|
||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ;")->link());
|
||||
}
|
||||
}
|
||||
|
||||
void simplifyString() {
|
||||
|
@ -7617,6 +7655,15 @@ private:
|
|||
" a<> b;\n"
|
||||
" b.a<>::c();\n"
|
||||
"}\n"))
|
||||
|
||||
// #9138
|
||||
ASSERT_NO_THROW(tokenizeAndStringify(
|
||||
"template <typename> struct a;\n"
|
||||
"template <bool> using c = int;\n"
|
||||
"template <bool b> c<b> d;\n"
|
||||
"template <> struct a<int> {\n"
|
||||
"template <typename e> constexpr auto g() { d<0 || e::f>; return 0; }\n"
|
||||
"};\n"))
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue