Fixed #9892 (Crash: endless recursion in Token::typeDecl for expression 'auto combo = widget->combo = new Combo{};')

This commit is contained in:
Daniel Marjamäki 2020-09-11 21:29:48 +02:00
parent 61145cf878
commit e03a8e1dc1
2 changed files with 14 additions and 1 deletions

View File

@ -2162,7 +2162,7 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token * tok)
const Token * tok2 = var->declEndToken();
if (Token::Match(tok2, "; %varid% =", var->declarationId()))
tok2 = tok2->tokAt(2);
if (Token::simpleMatch(tok2, "=") && tok2->astOperand2()) {
if (Token::simpleMatch(tok2, "=") && Token::Match(tok2->astOperand2(), "!!=")) {
std::pair<const Token*, const Token*> r = typeDecl(tok2->astOperand2());
if (r.first)
return r;

View File

@ -430,6 +430,7 @@ private:
TEST_CASE(auto11); // #8964 - const auto startX = x;
TEST_CASE(auto12); // #8993 - const std::string &x; auto y = x; if (y.empty()) ..
TEST_CASE(auto13);
TEST_CASE(auto14);
TEST_CASE(unionWithConstructor);
@ -7789,6 +7790,18 @@ private:
ASSERT(tok->variable()->valueType()->pointer);
}
void auto14() { // #9892 - crash in Token::declType
GET_SYMBOL_DB("static void foo() {\n"
" auto combo = widget->combo = new Combo{};\n"
" combo->addItem();\n"
"}");
const Token *tok;
tok = Token::findsimplematch(tokenizer.tokens(), "combo =");
ASSERT(tok && !tok->valueType());
}
void unionWithConstructor() {
GET_SYMBOL_DB("union Fred {\n"
" Fred(int x) : i(x) { }\n"