From 56e17fb2287fef9b9ef4c5511975aaf0487d6db2 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 7 Dec 2019 14:06:45 -0600 Subject: [PATCH] Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. (#2432) --- lib/tokenlist.cpp | 14 +++++++------- test/testtokenize.cpp | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 4bd270c16..eb42119e9 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a9821eb1f..610545bc3 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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")) }