Tokenizer: set links for <> in 'a=new b<c>;' code

This commit is contained in:
Daniel Marjamäki 2013-12-29 15:37:27 +01:00
parent f2661dae4c
commit 41e4194573
2 changed files with 17 additions and 1 deletions

View File

@ -3197,7 +3197,7 @@ void Tokenizer::createLinks2()
else if (token->str() == ">" || token->str() == ">>") {
if (type.empty() || type.top()->str() != "<") // < and > don't match.
continue;
if (token->next() && !Token::Match(token->next(), "%var%|>|&|*|::|,|(|)|{"))
if (token->next() && !Token::Match(token->next(), "%var%|>|&|*|::|,|(|)|{|;"))
continue;
// Check type of open link
@ -3205,6 +3205,15 @@ void Tokenizer::createLinks2()
continue;
}
// if > is followed by ; .. "new a<b>;" is expected
if (Token::Match(token->next(), ";")) {
Token *prev = type.top()->previous();
while (prev && Token::Match(prev->previous(), ":: %var%"))
prev = prev->tokAt(-2);
if (!prev || !prev->previous() || prev->previous()->str() != "new")
continue;
}
Token* top = type.top();
type.pop();
if (token->str() == ">>" && type.top()->str() != "<") {

View File

@ -2878,6 +2878,13 @@ private:
ASSERT_EQUALS("void f ( ) { int a ; a = b < T < char , 3 > , int > ( ) ; }", tok(code));
}
{
const char code[] = "void f() {\n"
" a = new std::map<std::string, std::string>;\n"
"}\n";
ASSERT_EQUALS("void f ( ) { a = new std :: map < std :: string , std :: string > ; }", tok(code));
}
{
// ticket #1327
const char code[] = "const C<1,2,3> foo ()\n"