From 9c5a136f049e405fccbe8dfae7a7556eef93a0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 3 Apr 2017 21:48:22 +0200 Subject: [PATCH] Fixed #7975 (crash: Tokenizer::createLinks2 problem with enable_if) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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() {