Skip to content

Commit 56e17fb

Browse files
pfultz2danmar
authored andcommitted
Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. (#2432)
1 parent 047418d commit 56e17fb

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

lib/tokenlist.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,11 @@ static bool iscpp11init_impl(const Token * const tok)
601601
return true;
602602
}
603603

604-
static bool isRefQualifier(const Token* tok)
604+
static bool isQualifier(const Token* tok)
605605
{
606-
if (!Token::Match(tok, "&|&&"))
607-
return false;
608-
if (!Token::Match(tok->next(), "{|;"))
606+
while (Token::Match(tok, "&|&&|*"))
607+
tok = tok->next();
608+
if (!Token::Match(tok, "{|;"))
609609
return false;
610610
return true;
611611
}
@@ -977,7 +977,7 @@ static void compileMulDiv(Token *&tok, AST_state& state)
977977
{
978978
compilePointerToElem(tok, state);
979979
while (tok) {
980-
if (Token::Match(tok, "[/%]") || (tok->str() == "*" && !tok->astOperand1())) {
980+
if (Token::Match(tok, "[/%]") || (tok->str() == "*" && !tok->astOperand1() && !isQualifier(tok))) {
981981
if (Token::Match(tok, "* [*,)]")) {
982982
Token* tok2 = tok->next();
983983
while (tok2->next() && tok2->str() == "*")
@@ -1036,7 +1036,7 @@ static void compileAnd(Token *&tok, AST_state& state)
10361036
{
10371037
compileEqComp(tok, state);
10381038
while (tok) {
1039-
if (tok->str() == "&" && !tok->astOperand1() && !isRefQualifier(tok)) {
1039+
if (tok->str() == "&" && !tok->astOperand1() && !isQualifier(tok)) {
10401040
Token* tok2 = tok->next();
10411041
if (!tok2)
10421042
break;
@@ -1075,7 +1075,7 @@ static void compileLogicAnd(Token *&tok, AST_state& state)
10751075
{
10761076
compileOr(tok, state);
10771077
while (tok) {
1078-
if (tok->str() == "&&" && !isRefQualifier(tok)) {
1078+
if (tok->str() == "&&" && !isQualifier(tok)) {
10791079
if (!tok->astOperand1()) {
10801080
Token* tok2 = tok->next();
10811081
if (!tok2)

test/testtokenize.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8126,8 +8126,8 @@ class TestTokenizer : public TestFixture {
81268126
"}\n"))
81278127
}
81288128

8129-
// #9511
81308129
void checkRefQualifiers() {
8130+
// #9511
81318131
ASSERT_NO_THROW(tokenizeAndStringify("class a {\n"
81328132
" void b() && {\n"
81338133
" if (this) {}\n"
@@ -8166,6 +8166,15 @@ class TestTokenizer : public TestFixture {
81668166
" return x;\n"
81678167
" }\n"
81688168
"};\n"))
8169+
// #9524
8170+
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int* {\n"
8171+
" if (0) {}\n"
8172+
" return 0;\n"
8173+
"};\n"))
8174+
ASSERT_NO_THROW(tokenizeAndStringify("auto f() -> int** {\n"
8175+
" if (0) {}\n"
8176+
" return 0;\n"
8177+
"};\n"))
81698178

81708179
}
81718180

0 commit comments

Comments
 (0)