Skip to content

Commit 759c3b3

Browse files
committed
Fix primary-expression ( suffix parsing bug, closes #860
If a primary-expression is followed by `(` but -not- a parameter-list and `)`, then don't treat it as part of the primary-expression, it's something else (likely a local statement/block parameter list)
1 parent 479a345 commit 759c3b3

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.3.0 Build 8C17:1133
2+
cppfront compiler v0.3.0 Build 8C17:1632
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8C17:1133"
1+
"8C17:1632"

source/parse.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5686,6 +5686,9 @@ class parser
56865686
n->cap_grp->add(n.get());
56875687
}
56885688

5689+
// Remember current position, in case we need to backtrack
5690+
auto term_pos = pos;
5691+
56895692
auto term = postfix_expression_node::term{&curr()};
56905693
next();
56915694

@@ -5708,18 +5711,25 @@ class parser
57085711
}
57095712
else if (term.op->type() == lexeme::LeftParen)
57105713
{
5714+
// Next should be an expression-list followed by a ')'
5715+
// If not, then this wasn't a call expression so backtrack to
5716+
// the '(' which will be part of the next grammar production
5717+
57115718
term.expr_list = expression_list(term.op);
5712-
if (!term.expr_list) {
5713-
error("( is not followed by a valid expression list");
5714-
return {};
5719+
if (
5720+
term.expr_list
5721+
&& curr().type() == lexeme::RightParen
5722+
)
5723+
{
5724+
term.expr_list->close_paren = &curr();
5725+
term.op_close = &curr();
5726+
next();
57155727
}
5716-
if (curr().type() != lexeme::RightParen) {
5717-
error("unexpected text - ( is not properly matched by )", true, {}, true);
5718-
return {};
5728+
else
5729+
{
5730+
pos = term_pos; // backtrack
5731+
break;
57195732
}
5720-
term.expr_list->close_paren = &curr();
5721-
term.op_close = &curr();
5722-
next();
57235733
}
57245734
else if (term.op->type() == lexeme::Dot)
57255735
{

0 commit comments

Comments
 (0)