From 4c25e798b16ebb4c08bbc528089fb1f5a7807b20 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 31 Dec 2016 22:05:29 +0100 Subject: [PATCH] Fixed #7865 (Tokenizer::createLinks2(): does does set links for <> in struct template) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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() {