Fixed #8009 (Tokenizer: fix handling of template rvalue references)

This commit is contained in:
Daniel Marjamäki 2017-05-23 18:55:17 +02:00
parent 70c2de62b7
commit 93e0516291
2 changed files with 17 additions and 1 deletions

View File

@ -3062,7 +3062,9 @@ void Tokenizer::createLinks2()
} else if (token->str() == ">") { } else if (token->str() == ">") {
if (type.empty() || type.top()->str() != "<") // < and > don't match. if (type.empty() || type.top()->str() != "<") // < and > don't match.
continue; continue;
if (token->next() && !Token::Match(token->next(), "%name%|>|&|*|::|,|(|)|{|}|;|[|:")) if (token->next() &&
!Token::Match(token->next(), "%name%|>|&|*|::|,|(|)|{|}|;|[|:") &&
!Token::Match(token->next(), "&& %name% ="))
continue; continue;
// if > is followed by [ .. "new a<b>[" is expected // if > is followed by [ .. "new a<b>[" is expected

View File

@ -4568,6 +4568,19 @@ private:
ASSERT_EQUALS(true, tok1->link() == tok2); ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1); ASSERT_EQUALS(true, tok2->link() == tok1);
} }
{
// #8006
const char code[] = "C<int> && 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() { void simplifyString() {
@ -8121,6 +8134,7 @@ private:
ASSERT_EQUALS("static_casta(i[", testAst("; static_cast<char*>(a)[i];")); // #6203 ASSERT_EQUALS("static_casta(i[", testAst("; static_cast<char*>(a)[i];")); // #6203
ASSERT_EQUALS("reinterpret_castreinterpret_castptr(123&(", ASSERT_EQUALS("reinterpret_castreinterpret_castptr(123&(",
testAst(";reinterpret_cast<void*>(reinterpret_cast<unsigned>(ptr) & 123);")); // #7253 testAst(";reinterpret_cast<void*>(reinterpret_cast<unsigned>(ptr) & 123);")); // #7253
ASSERT_EQUALS("bcd.(=", testAst(";a<int> && 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. // 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<bool> { };")); ASSERT_EQUALS("Cpublica::b:::", testAst("class C : public ::a::b<bool> { };"));