Skip to content

Commit 863cd62

Browse files
wchilders-nvidiadaveedvdv-nvidia
authored andcommitted
Fix C++-generating back end issue with dependent multi-dimensional subscripts [GH #195]
1 parent a63fc0e commit 863cd62

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/5/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/5/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
@@ -15289,16 +15289,26 @@ it is a tpck_unknown_function constant and to NULL otherwise.
1528915289
} /* is_dot_static_operation */
1529015290

1529115291

15292-
static void gen_array_subscript(an_expr_node_ptr expr)
15292+
static void gen_array_subscript_list(an_expr_node_ptr expr)
1529315293
/*
15294-
Render the given expression surrounded by brackets.
15294+
Put out the given expression list surrounded by square brackets.
1529515295
*/
1529615296
{
15297+
a_boolean first = TRUE;
15298+
1529715299
write_tok_ch('[');
15298-
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
15299-
/*obj_expr_of_mfunc_operator=*/FALSE);
15300+
while (expr != NULL) {
15301+
if (first) {
15302+
first = FALSE;
15303+
} else {
15304+
write_tok_str(", ");
15305+
} /* if */
15306+
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
15307+
/*obj_expr_of_mfunc_operator=*/FALSE);
15308+
expr = expr->next;
15309+
} /* if */
1530015310
write_tok_ch(']');
15301-
} /* gen_array_subscript */
15311+
} /* gen_array_subscript_list */
1530215312

1530315313

1530415314
static void gen_va_arg(an_expr_node_ptr expr)
@@ -17886,7 +17896,7 @@ handled through recursion.
1788617896
break;
1788717897
case eok_subscript:
1788817898
gen_member_selector_for_builtin_offsetof(arg1);
17889-
gen_array_subscript(arg2);
17899+
gen_array_subscript_list(arg2);
1789017900
break;
1789117901
case eok_cast:
1789217902
case eok_base_class_cast:
@@ -19279,7 +19289,7 @@ gen_expr that might end up generating this expr as a temporary.
1927919289
parens_may_be_needed(generated_precedence[eok_subscript],
1928019290
operand_1),
1928119291
/*obj_expr_of_mfunc_operator=*/FALSE);
19282-
gen_array_subscript(operand_2);
19292+
gen_array_subscript_list(operand_2);
1928319293
goto done_with_operation;
1928419294
case eok_cli_subscript:
1928519295
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)