diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 978b7dc08..cb3122ff6 100755 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a668c07f0..8ea6ea229 100755 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 d;";