Tweak fix for ticket #8297

This commit is contained in:
Daniel Marjamäki 2017-12-17 22:27:05 +01:00
parent 1428759479
commit 9c17bddbd4
2 changed files with 24 additions and 6 deletions

View File

@ -3239,24 +3239,30 @@ void Tokenizer::createLinks2()
// Then this is probably a template instantiation if either "B" or "C" has comparisons
if (token->tokType() == Token::eLogicalOp && !type.empty() && type.top()->str() == "<") {
const Token *prev = token->previous();
while (Token::Match(prev, "%name%|%num%|%str%|%cop%|)|]")) {
bool foundComparison = false;
while (Token::Match(prev, "%name%|%num%|%str%|%cop%|)|]") && prev != type.top()) {
if (prev->str() == ")" || prev->str() == "]")
prev = prev->link();
else if (prev->tokType() == Token::eLogicalOp || prev->isComparisonOp())
else if (prev->tokType() == Token::eLogicalOp)
break;
else if (prev->isComparisonOp())
foundComparison = true;
prev = prev->previous();
}
if (prev && prev != type.top() && prev->isComparisonOp())
if (prev == type.top() && foundComparison)
continue;
const Token *next = token->next();
while (Token::Match(next, "%name%|%num%|%str%|%cop%|(|[")) {
foundComparison = false;
while (Token::Match(next, "%name%|%num%|%str%|%cop%|(|[") && next->str() != ">") {
if (next->str() == "(" || next->str() == "[")
next = next->link();
else if (next->tokType() == Token::eLogicalOp || next->isComparisonOp())
else if (next->tokType() == Token::eLogicalOp)
break;
else if (next->isComparisonOp())
foundComparison = true;
next = next->next();
}
if (next && next != type.top() && next->isComparisonOp() && next->str() != ">")
if (next && next->str() == ">" && foundComparison)
continue;
}

View File

@ -4522,6 +4522,18 @@ private:
ASSERT_EQUALS(true, tok->linkAt(3) == nullptr);
}
{
// if (a < ... > d) { }
const char code[] = "if (a < b || c == 3 || d > e);";
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(3) == nullptr);
}
{
// template
const char code[] = "a<b==3 || c> d;";