diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8f7f86cb0..4eb47620b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3035,7 +3035,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, "struct|class %name% [:<]")) isStruct = true; else if (Token::Match(token, "[;{}]")) isStruct = false; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index faf9662be..b98d8871e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4531,6 +4531,21 @@ private: ASSERT_EQUALS(true, tok->link() == tok->tokAt(4)); ASSERT_EQUALS(true, tok->linkAt(4) == tok); } + + { + // #7865 + const char code[] = "template \n" + "struct CheckedDivOp< T, U, typename std::enable_if::value || std::is_floating_point::value>::type> {\n" + "};\n"; + errout.str(""); + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "struct")->tokAt(2); + const Token *tok2 = Token::findsimplematch(tokenizer.tokens(), "{")->previous(); + ASSERT_EQUALS(true, tok1->link() == tok2); + ASSERT_EQUALS(true, tok2->link() == tok1); + } } void simplifyString() {