From 62bc827eb0e02a52ff93ad21e5fa573034010b55 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 6 Nov 2015 10:44:37 +0100 Subject: [PATCH] Fixed createLinks2() when inheriting from a template (#6601) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 41ffaf3d3..aeb84660f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3025,7 +3025,7 @@ void Tokenizer::createLinks2() else if (token->str() == ">") { if (type.empty() || type.top()->str() != "<") // < and > don't match. continue; - if (token->next() && !Token::Match(token->next(), "%name%|>|&|*|::|,|(|)|{|;|[")) + if (token->next() && !Token::Match(token->next(), "%name%|>|&|*|::|,|(|)|{|;|[|:")) continue; // if > is followed by [ .. "new a[" is expected diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c0c0d40be..bdb85d728 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4489,6 +4489,24 @@ private: ASSERT_EQUALS(true, tok->linkAt(3) == nullptr); } + + { + // #6601 + const char code[] = "template struct FuncType : FuncType { };"; + errout.str(""); + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + const Token *tok = tokenizer.tokens(); + + ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4)); // + ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(14)); // + ASSERT_EQUALS(true, tok->linkAt(9) == tok->tokAt(11)); // (&) + ASSERT_EQUALS(true, tok->linkAt(12) == tok->tokAt(13)); // () + ASSERT_EQUALS(true, tok->linkAt(17) == tok->tokAt(21)); // + ASSERT_EQUALS(true, tok->linkAt(19) == tok->tokAt(20)); // () + ASSERT_EQUALS(true, tok->linkAt(22) == tok->tokAt(23)); // {} + } } void simplifyString() {