diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 939de80ca..eeaf5f3ee 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3034,7 +3034,7 @@ void Tokenizer::createLinks2() std::stack type; for (Token *token = list.front(); token; token = token->next()) { - if (Token::Match(token, "struct|class %name% [:<]")) + if (Token::Match(token, "%name%|> %name% [:<]")) isStruct = true; else if (Token::Match(token, "[;{}]")) isStruct = false; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index fca695793..12d0d54cf 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4569,6 +4569,19 @@ private: ASSERT_EQUALS(true, tok1->link() == tok2); ASSERT_EQUALS(true, tok2->link() == tok1); } + + { + // #7975 + const char code[] = "template X copy() {};\n"; + errout.str(""); + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "< Y"); + const Token *tok2 = Token::findsimplematch(tok1, "> copy"); + ASSERT_EQUALS(true, tok1->link() == tok2); + ASSERT_EQUALS(true, tok2->link() == tok1); + } } void simplifyString() {