Skip to content

Commit 7a3eacd

Browse files
Fix C++-generating back end issue with dependent multi-dimensional subscripts [GH #195]
1 parent fe7f998 commit 7a3eacd

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

‎src/Changes‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
Version 7.1
22

3+
10/1/26 [GH #195]
4+
C++-generating back end: dependent multi-dimensional subscripts
5+
6+
In cases in which template definitions are generated from the prototype
7+
instantiation IL, when a dependent multi-dimensional subscript operation
8+
appears in a template definition, the C++-generating back end previously
9+
emitted only the first subscript. This is now fixed. For example, with
10+
--c++23:
11+
12+
template<typename T> auto f(const T &t) {
13+
return t[1, 2]; // Previously generated as "t[1]"
14+
}
15+
16+
317
10/1/26 [GH #191]
418
C++-generating back end: inaccessible or out-of-scope template arguments
519

‎src/cp_gen_be.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15279,16 +15279,26 @@ it is a tpck_unknown_function constant and to NULL otherwise.
1527915279
} /* is_dot_static_operation */
1528015280

1528115281

15282-
static void gen_array_subscript(an_expr_node_ptr expr)
15282+
static void gen_array_subscript_list(an_expr_node_ptr expr)
1528315283
/*
15284-
Render the given expression surrounded by brackets.
15284+
Put out the given expression list surrounded by square brackets.
1528515285
*/
1528615286
{
15287+
a_boolean first = TRUE;
15288+
1528715289
write_tok_ch('[');
15288-
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
15289-
/*obj_expr_of_mfunc_operator=*/FALSE);
15290+
while (expr != NULL) {
15291+
if (first) {
15292+
first = FALSE;
15293+
} else {
15294+
write_tok_str(", ");
15295+
} /* if */
15296+
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
15297+
/*obj_expr_of_mfunc_operator=*/FALSE);
15298+
expr = expr->next;
15299+
} /* if */
1529015300
write_tok_ch(']');
15291-
} /* gen_array_subscript */
15301+
} /* gen_array_subscript_list */
1529215302

1529315303

1529415304
static void gen_va_arg(an_expr_node_ptr expr)
@@ -17876,7 +17886,7 @@ handled through recursion.
1787617886
break;
1787717887
case eok_subscript:
1787817888
gen_member_selector_for_builtin_offsetof(arg1);
17879-
gen_array_subscript(arg2);
17889+
gen_array_subscript_list(arg2);
1788017890
break;
1788117891
case eok_cast:
1788217892
case eok_base_class_cast:
@@ -19269,7 +19279,7 @@ gen_expr that might end up generating this expr as a temporary.
1926919279
parens_may_be_needed(generated_precedence[eok_subscript],
1927019280
operand_1),
1927119281
/*obj_expr_of_mfunc_operator=*/FALSE);
19272-
gen_array_subscript(operand_2);
19282+
gen_array_subscript_list(operand_2);
1927319283
goto done_with_operation;
1927419284
case eok_cli_subscript:
1927519285
gen_expr_with_parens(operand_1);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpfe -DTEST_NUMBER=1 --c++23 Test_name.c
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//options_all:--c++23
2+
//type:cp
3+
template<typename T> auto f(const T &t) {
4+
return t[1, 2]; // Previously generated as "t[1]"
5+
}
6+
struct S {
7+
int operator[](int, int) const;
8+
} s;
9+
int i = f(s);

0 commit comments

Comments
 (0)