Skip to content

Commit c181fb1

Browse files
committed
Default initialize function argument
1 parent 130f149 commit c181fb1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

source/parse.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ struct expression_list_node
661661
token const* open_paren = {};
662662
token const* close_paren = {};
663663
bool inside_initializer = false;
664+
bool default_initializer = false;
664665

665666
struct term {
666667
passing_style pass = {};
@@ -5393,6 +5394,7 @@ class parser
53935394
};
53945395
mutable std::vector<function_body_extent> function_body_extents;
53955396
mutable bool is_function_body_extents_sorted = false;
5397+
bool is_inside_call_expr = false;
53965398

53975399
public:
53985400
auto is_within_function_body(source_position p) const
@@ -5747,6 +5749,8 @@ class parser
57475749
expr_list->inside_initializer = false;
57485750
}
57495751
n->expression_list_is_fold_expression = expr_list->is_fold_expression();
5752+
expr_list->default_initializer =
5753+
is_inside_call_expr && std::empty(expr_list->expressions);
57505754
n->expr = std::move(expr_list);
57515755
return n;
57525756
}
@@ -5899,8 +5903,12 @@ class parser
58995903
// Next should be an expression-list followed by a ')'
59005904
// If not, then this wasn't a call expression so backtrack to
59015905
// the '(' which will be part of the next grammar production
5906+
is_inside_call_expr = true;
59025907

59035908
term.expr_list = expression_list(term.op, lexeme::RightParen);
5909+
5910+
is_inside_call_expr = false;
5911+
59045912
if (
59055913
term.expr_list
59065914
&& curr().type() == lexeme::RightParen

source/to_cpp1.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,11 @@ class cppfront
39593959
)
39603960
-> void
39613961
{ STACKINSTR
3962+
if (n.default_initializer) {
3963+
printer.print_cpp2("{}", n.position());
3964+
return;
3965+
}
3966+
39623967
auto add_parens =
39633968
should_add_expression_list_parens()
39643969
&& !n.inside_initializer

0 commit comments

Comments
 (0)