Skip to content

Commit 0905c02

Browse files
Fix C++-generating back end issue with dependent multi-dimensional subscripts [GH #195]
1 parent 57dc7ef commit 0905c02

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
@@ -15281,16 +15281,26 @@ it is a tpck_unknown_function constant and to NULL otherwise.
1528115281
} /* is_dot_static_operation */
1528215282

1528315283

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

1529515305

1529615306
static void gen_va_arg(an_expr_node_ptr expr)
@@ -17878,7 +17888,7 @@ handled through recursion.
1787817888
break;
1787917889
case eok_subscript:
1788017890
gen_member_selector_for_builtin_offsetof(arg1);
17881-
gen_array_subscript(arg2);
17891+
gen_array_subscript_list(arg2);
1788217892
break;
1788317893
case eok_cast:
1788417894
case eok_base_class_cast:
@@ -19271,7 +19281,7 @@ gen_expr that might end up generating this expr as a temporary.
1927119281
parens_may_be_needed(generated_precedence[eok_subscript],
1927219282
operand_1),
1927319283
/*obj_expr_of_mfunc_operator=*/FALSE);
19274-
gen_array_subscript(operand_2);
19284+
gen_array_subscript_list(operand_2);
1927519285
goto done_with_operation;
1927619286
case eok_cli_subscript:
1927719287
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)