Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. (#2432)

This commit is contained in:
Paul Fultz II 2019-12-07 14:06:45 -06:00 committed by Daniel Marjamäki
parent 047418dda1
commit 56e17fb228
2 changed files with 17 additions and 8 deletions

View File

@ -601,11 +601,11 @@ static bool iscpp11init_impl(const Token * const tok)
return true;
}
static bool isRefQualifier(const Token* tok)
static bool isQualifier(const Token* tok)
{
if (!Token::Match(tok, "&|&&"))
return false;
if (!Token::Match(tok->next(), "{|;"))
while (Token::Match(tok, "&|&&|*"))
tok = tok->next();
if (!Token::Match(tok, "{|;"))
return false;
return true;
}
@ -977,7 +977,7 @@ static void compileMulDiv(Token *&tok, AST_state& state)
{
compilePointerToElem(tok, state);
while (tok) {
if (Token::Match(tok, "[/%]") || (tok->str() == "*" && !tok->astOperand1())) {
if (Token::Match(tok, "[/%]") || (tok->str() == "*" && !tok->astOperand1() && !isQualifier(tok))) {
if (Token::Match(tok, "* [*,)]")) {
Token* tok2 = tok->next();
while (tok2->next() && tok2->str() == "*")
@ -1036,7 +1036,7 @@ static void compileAnd(Token *&tok, AST_state& state)
{
compileEqComp(tok, state);
while (tok) {
if (tok->str() == "&" && !tok->astOperand1() && !isRefQualifier(tok)) {
if (tok->str() == "&" && !tok->astOperand1() && !isQualifier(tok)) {
Token* tok2 = tok->next();
if (!tok2)
break;
@ -1075,7 +1075,7 @@ static void compileLogicAnd(Token *&tok, AST_state& state)
{
compileOr(tok, state);
while (tok) {
if (tok->str() == "&&" && !isRefQualifier(tok)) {
if (tok->str() == "&&" && !isQualifier(tok)) {
if (!tok->astOperand1()) {
Token* tok2 = tok->next();
if (!tok2)

View File

@ -8126,8 +8126,8 @@ private:
"}\n"))
}
// #9511
void checkRefQualifiers() {
// #9511
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
" void b() && {\n"
" if (this) {}\n"
@ -8166,6 +8166,15 @@ private:
" return x;\n"
" }\n"
"};\n"))
// #9524
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int* {\n"
" if (0) {}\n"
" return 0;\n"
"};\n"))
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int** {\n"
" if (0) {}\n"
" return 0;\n"
"};\n"))
}