Merge pull request #2739 from dan-42/fix_ticket_9839_ast_error

Fix ticket 9839: AST broken; range for loop that uses decltype
This commit is contained in:
Daniel Marjamäki 2020-08-18 21:59:50 +02:00 committed by GitHub
commit 6446790d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -485,6 +485,9 @@ static Token * skipDecl(Token *tok)
} else if (Token::Match(vartok, "%var% [:=(]")) {
return vartok;
}
else if (Token::simpleMatch(vartok, "decltype (")) {
return vartok->linkAt(1)->next();
}
vartok = vartok->next();
}
return tok;

View File

@ -6291,6 +6291,10 @@ private:
" for (const auto & e : array)\n"
" foo(e);\n"
" }\n"
" void f3() {\n"
" for (decltype(auto) e : array)\n"
" foo(e);\n"
" }\n"
"};");
ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Fred::f2' can be const.\n", errout.str());
}

View File

@ -7538,6 +7538,7 @@ private:
ASSERT_EQUALS("forx0=y(8<z;;(", testAst("for (x=0;(int)y<8;z);"));
ASSERT_EQUALS("forab,c:(", testAst("for (auto [a,b]: c);"));
ASSERT_EQUALS("fora*++;;(", testAst("for (++(*a);;);"));
ASSERT_EQUALS("foryz:(", testAst("for (decltype(x) *y : z);"));
// problems with multiple expressions
ASSERT_EQUALS("ax( whilex(", testAst("a(x) while (x)"));