Fixed #1955 (cppcheck hangs with 100% cpu load)

This commit is contained in:
Daniel Marjamäki 2010-08-18 22:22:14 +02:00
parent 1fd773b245
commit 0934035fcf
2 changed files with 21 additions and 1 deletions

View File

@ -1768,13 +1768,25 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
}
else if (indentlevel == 1 && Token::Match(tok2, ") = delete|default ;"))
{
const Token *end = tok2->tokAt(4);
Token * const end = tok2->tokAt(4);
tok2 = tok2->link()->previous();
// operator ==|>|<|..
if (Token::Match(tok->previous(), "operator %any%"))
tok2 = tok2->previous();
else if (Token::simpleMatch(tok2->tokAt(-2), "operator [ ]"))
tok2 = tok2->tokAt(-2);
else if (Token::simpleMatch(tok2->tokAt(-2), "operator ( )"))
tok2 = tok2->tokAt(-2);
else if (Token::simpleMatch(tok2->tokAt(-3), "operator delete [ ]"))
tok2 = tok2->tokAt(-3);
while ((tok2->isName() && tok2->str().find(":") == std::string::npos) ||
Token::Match(tok2, "[&*~]"))
tok2 = tok2->previous();
if (Token::Match(tok2, "[;{}]") || tok2->isName())
Token::eraseTokens(tok2, end);
tok2 = end;
}
}
}

View File

@ -3884,6 +3884,14 @@ private:
ASSERT_EQUALS("struct foo { }", tokenizeAndStringify(code));
}
{
const char *code = "struct A {"
" void operator delete (void *) = delete;"
" void operator delete[] (void *) = delete;"
"}";
ASSERT_EQUALS("struct A { }", tokenizeAndStringify(code));
}
{
const char *code = "struct foo {"
" foo();"