From 93e05162912c5270eff80382ed1d457c7222a10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 23 May 2017 18:55:17 +0200 Subject: [PATCH] Fixed #8009 (Tokenizer: fix handling of template rvalue references) --- lib/tokenize.cpp | 4 +++- test/testtokenize.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 88d912f75..c6eed8103 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3062,7 +3062,9 @@ 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%|>|&|*|::|,|(|)|{|}|;|[|:") && + !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 2c08ad054..2d131a5d6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4568,6 +4568,19 @@ private: ASSERT_EQUALS(true, tok1->link() == tok2); ASSERT_EQUALS(true, tok2->link() == tok1); } + + { + // #8006 + const char code[] = "C && a = b;"; + errout.str(""); + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + const Token *tok1 = tokenizer.tokens()->next(); + const Token *tok2 = tok1->tokAt(2); + ASSERT_EQUALS(true, tok1->link() == tok2); + ASSERT_EQUALS(true, tok2->link() == tok1); + } } void simplifyString() { @@ -8121,6 +8134,7 @@ private: ASSERT_EQUALS("static_casta(i[", testAst("; static_cast(a)[i];")); // #6203 ASSERT_EQUALS("reinterpret_castreinterpret_castptr(123&(", testAst(";reinterpret_cast(reinterpret_cast(ptr) & 123);")); // #7253 + ASSERT_EQUALS("bcd.(=", testAst(";a && b = c->d();")); // This two unit tests were added to avoid a crash. The actual correct AST result for non-executable code has not been determined so far. ASSERT_EQUALS("Cpublica::b:::", testAst("class C : public ::a::b { };"));