diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d0cb6d8ba..9aad928d5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3244,10 +3244,12 @@ void Tokenizer::createLinks2() if (Token::Match(token, "{|[|(")) type.push(token); else if (!type.empty() && Token::Match(token, "}|]|)")) { - while (type.top()->str() == "<") + while (type.top()->str() == "<") { + if (templateToken && templateToken->next() == type.top()) + templateToken = nullptr; type.pop(); + } type.pop(); - templateToken = nullptr; } else token->link(nullptr); } else if (!templateToken && !isStruct && Token::Match(token, "%oror%|&&|;")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 46c666ddf..a5c822b4e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4716,6 +4716,16 @@ private: const Token *A = Token::findsimplematch(tokenizer.tokens(), "A <"); ASSERT_EQUALS(true, A->next()->link() == A->tokAt(3)); } + { + // #8851 + const char code[] = "template::type>" + "void basic_json() {}"; + errout.str(""); + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->next()->link(), "> void")); + } } void simplifyString() {