diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5c2a17bc1..38ca70571 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3171,7 +3171,7 @@ void Tokenizer::createLinks2() else if (token->str() == ">" || token->str() == ">>") { if (type.empty() || type.top()->str() != "<") // < and > don't match. continue; - if (token->next() && !token->next()->isName() && !Token::Match(token->next(), ">|&|*|::|,|(|)")) + if (token->next() && !Token::Match(token->next(), "%var%|>|&|*|::|,|(|)|{")) continue; // Check type of open link diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7161764f3..c14161fec 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6441,6 +6441,23 @@ private: ASSERT_EQUALS("", errout.str()); } + + { + // #4860 + const char code[] = "class A : public B {};"; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + const Token *tok = tokenizer.tokens(); + + // B<..> + ASSERT_EQUALS(true, tok->tokAt(5) == tok->linkAt(7)); + ASSERT_EQUALS(true, tok->linkAt(5) == tok->tokAt(7)); + + ASSERT_EQUALS("", errout.str()); + } } void removeExceptionSpecification1() {